PHP | SOAP 1.2 |如何设置WS寻址

时间:2017-09-06 13:07:53

标签: php soap soap-client wshttpbinding soap1.2

这是WSDL ...

我在PHP中使用SOAP客户端,文档为HERE ...

肥皂电话

$wsdl = 'https://api.krollcorp.com/EBusinessTest/Kroll.Dealer.EBusiness.svc/Docs?singleWsdl';

try {
    $client = new SoapClient($wsdl, array('soap_version' => SOAP_1_2, 'trace' => 1));
    // $result = $client->SubmitPurchaseOrder();
    $result = $client->__soapCall("SubmitPurchaseOrder", array());
} catch (SoapFault $e) {
    printf("\nERROR: %s\n", $e->getMessage());
}

$requestHeaders = $client->__getLastRequestHeaders();
$request = $client->__getLastRequest();
$responseHeaders = $client->__getLastResponseHeaders();
printf("\nRequest Headers -----\n");
print_r($requestHeaders);
printf("\nRequest -----\n");
print_r($request);
printf("\nResponse Headers -----\n");
print_r($responseHeaders);
printf("\nEND\n");

输出

ERROR: The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/IEBusinessService/SubmitPurchaseOrder'.

Request Headers -----
POST /EBusinessTest/Kroll.Dealer.EBusiness.svc HTTP/1.1
Host: api.krollcorp.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.6.19
Content-Type: application/soap+xml; charset=utf-8; action="http://tempuri.org/IEBusinessService/SubmitPurchaseOrder"
Content-Length: 200


Request -----
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://tempuri.org/"><env:Body><ns1:SubmitPurchaseOrder/></env:Body></env:Envelope>

Response Headers -----
HTTP/1.1 500 Internal Server Error
Content-Length: 637
Content-Type: application/soap+xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 06 Sep 2017 12:42:57 GMT

END

尝试

我是使用SOAP API的初学者。

我认为这是失败的,因为SOAP 1.2使用WsHttpBinding而不是BasicHttpBinding。

我不确定如何在PHP中使用SOAP客户端设置WS寻址...

3 个答案:

答案 0 :(得分:3)

以下代码对我有用。您可以启用Ws-A寻址并调用soap方法-

{!! Form::open(array('url' => '/xyz','files' => true)) !!}
{!! Form::close() !!}

答案 1 :(得分:0)

老兄,我完全感受到你的痛苦。我能够让这个工作,但我不认为这是正确的方法,但它指向正确的方向。但需要注意的是,您必须知道soap_client将分配给寻址的命名空间。最好的方法就是捕获请求XML并查找哪些命名空间附加到地址,然后传入。下面是我的代码,默认为'ns2'用于命名空间,但你不能指望它为你的例。祝你好运!

fig, ax = plt.subplots(subplot_kw=dict(projection="3d"))
ax.scatter(position1[:,0], position1[:,1], position1[:,2], marker='.')
ax.scatter(position2[:,0], position2[:,1], position2[:,2], marker='.')
plt.show()

答案 2 :(得分:0)

我的解决方法是

  1. 使用SoapUi发送请求
  2. 从SoapUi屏幕(SoapUi程序底部)复制请求http日志
  3. 将该代码作为休止符粘贴到PHP项目中

    $ soap_request =' {从SoapUi http日志复制该部分} ';

        $WSDL = "**wsdl adres**";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER,         false);
        curl_setopt($ch, CURLOPT_URL,            $WSDL);
        curl_setopt($ch, CURLOPT_FAILONERROR,    true);
        curl_setopt($ch, CURLOPT_HTTPHEADER,     Array(
            'Content-Type: application/soap+xml; charset=utf-8',
            'SOAPAction: "run"',
            'Accept: text/xml',
            'Cache-Control: no-cache',
            'Pragma: no-cache',
            'Content-length: '. strlen($soap_request),
            'User-Agent: PHP-SOAP/7.0.10',
        ));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($ch, CURLOPT_TIMEOUT,        30);
        curl_setopt($ch, CURLOPT_POSTFIELDS,     $soap_request);
        $response = curl_exec($ch);
        if (empty($response)) {
            throw new SoapFault('CURL error: '.curl_error($ch), curl_errno($ch));
        }
        curl_close($ch);