【问题标题】:How to make a php SOAP call如何进行 php SOAP 调用
【发布时间】:2017-06-25 02:58:49
【问题描述】:

我在设置 PHP SOAP 调用的主体时遇到问题。我相信我很接近只是不知道如何以正确的格式获取它。

这是我目前在 PHP 中所拥有的

    $client = new SoapClient('http://url');
    $username='username';
    $password='password';

    $headers='
        '.$username.'
        '.$password.'
    ';

    $securityTags = new SoapVar($headers, XSD_ANYXML);

    $header=new SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security",$securityTags,true);

    $client->__setSoapHeaders(array($header));

    //HOW DO I SET THE BODY????
    $params = array('deal'=>'PT10M', 'StoreIds'=>64);
    return $client->__soapCall("PullDeals", array('searchCriteria'=>$params));

下面是请求的样子

<soapenv:Envelope xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:deal="http://url.com" xmlns:ns="http://url" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken wsu:Id="UsernameToken-145" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>YOUR_USERNAME</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">YOUR_PASSWORD</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">JQT6P7Zd3COZerXkREww2g==</wsse:Nonce>
            <wsu:Created>2013-11-19T22:18:54.122Z</wsu:Created>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <ns:PullDeals>
         <ns:searchCriteria>
            <deal:MaxElapsedSinceUpdate>PT10M</deal:MaxElapsedSinceUpdate>           
            <deal:StoreIds><arr:long>64</arr:long></deal:StoreIds>
         </ns:searchCriteria>
      </ns:PullDeals>
   </soapenv:Body>
</soapenv:Envelope>

【问题讨论】:

    标签: php soap soap-client wsse


    【解决方案1】:

    要将您的请求与请求的外观进行比较,请将'trace' =&gt; true 添加到您的soap 客户端。

    $client = new SoapClient("my.wsdl", array('trace' =&gt; true));

    and then use echo $client-&gt;__getLastRequest(); to spit out the XML.

    我通常只是在带有 chrome 的 Inspector 的页面上查看它,以看到它很好地缩进。

    您可以在看到它的形成方式后相应地重新格式化您的呼叫。

    Failing that you can hard code the XML.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多