如何在PHP中更改SOAP命名空间以匹配WSDL?

Sha*_*uck 1 php soap wsdl

我目前正在为我工​​作的公司开展一个项目.该项目需要向另一家公司发出SOAP请求(通过PHP).我的PHP代码中的SoapClient与另一家公司的SOAP服务器进行通信,但我得到的只是"INVALID XML".在检查了它们的WSDL和响应之后,我注意到它们的命名空间是不同的.我需要更改我的命名空间以匹配他们的名称空间.

例如:我的请求中的标记显示"ns1".和"环境",但他们的"肥皂".

我怎么能改变这个?

这是我的代码示例,发出的请求和收到的响应.

---------------- CODE ----------------

  $client = new SoapClient("http://ws.example.com/test/test.asmx?WSDL", array('soap_version'=>SOAP_1_2, 'trace' => 1));

  $result = $client->TestFunction(array('Packet'=>'<Email>test@example.com</Email><Password>examplepassword</Password>'));

  $sessionid = $result->TestFunctionResult;

  print $sessionid;


  echo "REQUEST HEADER:\n" . htmlentities($client->__getLastRequestHeaders()) . "\n";

  echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n";

  echo "RESPONSE HEADER:\n" . htmlentities($client->__getLastResponseHeaders()) . "\n";

  echo "RESPONSE:\n" . htmlentities($client->__getLastResponse()) . "\n";


------------ REQUEST SENT -------------

POST /test/test.asmx HTTP/1.1
Host: ws.example.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.3.4
Content-Type: application/soap+xml; charset=utf-8; action="http://ws.example.com/test/TestFunction"
Content-Length: 352

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://ws.example.com/resumes/">
  <env:Body>
    <ns1:TestFunction>
      <ns1:Packet>
        <Email>test@example.com</Email>
        <Password>examplepassword</Password>
      </ns1:Packet>
    </ns1:TestFunction>
  </env:Body>
</env:Envelope>

---------- RESPONSE RECEIVED ----------

HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Length: 450
Content-Type: application/soap+xml; charset=utf-8
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
X-PBY: BEARWS2
Date: Mon, 18 Apr 2011 15:33:51 GMT
Connection: close

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <TestFunctionResponse xmlns="http://ws.example.com/test/">
      <TestFunctionResult>
        <Packet>
          <Error>Invalid XML</Error>
        </Packet>
      </TestFunctionResult>
    </TestFunctionResponse>
  </soap:Body>
</soap:Envelope>

Run Code Online (Sandbox Code Playgroud)


我怎样才能解决这个问题?

Way*_*ett 5

前缀名称无关紧要.它们不是你问题的原因.看起来你的标签不匹配:

<ns1:TestFunciton>
    <ns1:Packet>
        <Email>test@example.com</Email>
        <Password>examplepassword</Password>
    </ns1:Packet>
</ns1:TestFunction>
Run Code Online (Sandbox Code Playgroud)

注意拼写错误TestFunciton.