在.NET web服务上使用PHP SOAP客户端


Using PHP SOAP client on .NET web service

我正在尝试使用.NET SOAP服务,但目前只收到一个"false"响应。

访问服务端点告诉我以下内容:

The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
<?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>
            <SendData xmlns="http://tempuri.org/">
                <myObj>string</myObj>
            </SendData>
        </soap:Body>
    </soap:Envelope>

但当我检查我的请求时,它会发送以下信息:

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
       <SOAP-ENV:Body>
           <ns1:SendData>
               <ns1:myObj>My data</ns1:myObj>
           </ns1:SendData>
       </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

因此,我们可以看到我的请求具有不同的节点标题,并且还在参数中添加了"ns1:"。

这是我的(简要)PHP

$soap = new SoapClient('wsdl.xml', array("trace" => 1, "exception" => 1));
$call = $soap->__soapCall("SendData", array("SendData" => array("myObj" => "My data")));

所以我的问题是:请求模式的这种差异是导致请求失败的原因吗?还是这只是编写相同内容的另一种方式?如果它负责,是否可以完全按照端点指定的方式编写我的请求?

这是一回事。

在给定的示例中,<SendData xmlns="http://tempuri.org/">没有名称空间前缀(您自己请求中的ns1),因此使用默认前缀,并为其自身及其子体指定xmlns属性。

在您的请求中,ns1命名空间前缀是使用xmlns:ns1="http://tempuri.org/"定义的,并在<ns1:SendData>中使用。