PHP SOAP XML请求和响应

时间:2015-07-06 12:29:45

标签: php xml web-services soap asmx

我正在尝试使用PHP生成SOAP + XML请求:

要发布的数据信息如下:

发送请求的网址:https://www.somedomain.com/ws/ws_CardRequest_test.asmx

    POST /ws/ws_CardRequest_test.asmx HTTP/1.1
    Host: www.somedomain.com
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://tempuri.org/GetCardBalance"

请求如下:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <GetCardBalance xmlns="http://tempuri.org/">
          <UserID>string</UserID>
          <PWD>string</PWD>
          <CardID>int</CardID>
        </GetCardBalance>
      </soap:Body>
    </soap:Envelope>

如何生成完全相同的请求?

我现有的代码如下:

    $soapUrl = "https://www.somedomain.com/ws/ws_CardRequest_test.asmx";
    $login = "user";
    $password = "pwd";

    try{

        $opts = array(
            'http'=>array(
                'user_agent' => 'PHPSoapClient'
                )
            );

        $context = stream_context_create($opts);
        $client = new SoapClient($soapUrl,
                                 array('stream_context' => $context,
                                       'cache_wsdl' => WSDL_CACHE_NONE));

        $result = $client->checkVat(array( 'UserID'  => $login, 'PWD' => $password, 'CardID' => 18));
        pr($result);
    }
    catch(Exception $e){
        echo $e->getMessage();
    }

以上代码的输出:

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://www.somedomain.com/ws/ws_CardRequest_test.asmx">
    <SOAP-ENV:Body><ns1:Echo>
    <GetCardBalance><UserID>userid</UserID><PWD>pwd</PWD><CardID>18</CardID>
     </GetCardBalance></ns1:Echo>
     </SOAP-ENV:Body> 
     </SOAP-ENV:Envelope>

等待上述问题的确切解决方案。

0 个答案:

没有答案