PHP SOAP请求不对

时间:2012-04-24 11:38:56

标签: php soap xmlhttprequest soap-client

我尝试构建以下SOAP请求:

<?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>
    <CheckSomething xmlns="http://service.mydomain.com/">
      <User>
        <username>user123</username>
        <password>geheim</password>
      </User>
      <ItemXY>something</ItemXY>
    </CheckSomething>
  </soap:Body>
</soap:Envelope>

这是我的PHP代码

$soapClient = new SoapClient("http://service.mydomain.com/Services.asmx?wsdl",array( "trace" => 1 ));
$Param = array (
  'username' => "user123",
  'password' => "geheim"
);
$info = $soapClient->__call("CheckSomething", array("User" => $Param,"ItemXY" => "something"));
echo "Request :\n".htmlspecialchars($soapClient->__getLastRequest()) ."\n";

结果是:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://service.mydomain.com/">
<SOAP-ENV:Body>
<ns1:CheckSomething/>
<param1>something</param1>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是此服务的wsdl部分:

<s:element name="CheckSomething">
  <s:complexType>
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="User" type="tns:Validation"/>
      <s:element minOccurs="0" maxOccurs="1" name="ItemXY" type="s:string"/>
    </s:sequence>
  </s:complexType>
</s:element>

有人可以帮我形成正确的SOAP请求吗?

如何删除结果标记中的ns1并提供正确的数组用户和ItemXY?

1 个答案:

答案 0 :(得分:6)

我将PHP代码修改为:

$soapClient = new SoapClient("http://service.mydomain.com/Services.asmx?wsdl",array( "trace" => 1 ));
$user_param = array (
  'username' => "user123",
  'password' => "geheim"
);
$service_param = array (
  'User' => $user_param,
  "ItemXY" => "something"
);

$info = $soapClient->__call("CheckSomething", array($service_param));
echo "Request :\n".htmlspecialchars($soapClient->__getLastRequest()) ."\n";

它有效!