3

我尝试构建以下 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结果标签中的标签并给出正确的数组用户和项目XY?

4

1 回答 1

7

在我将 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";

有用!

于 2012-07-23T14:11:21.870 回答