2

我从网络服务收到以下响应

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><GetUserResponse xmlns="urn:wwservice"><userDetails xmlns="">Successfully write a web service hurray</userDetails></GetUserResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

但是我得到元素的 Apex 类型未找到:userDetails

这是我的 wsdl 文件

<?xml version="1.0" encoding="ISO-8859-1"?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:wwservice" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:wwservice">
<types>
<xsd:schema elementFormDefault="qualified" targetNamespace="urn:wwservice">
 <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
 <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
 <xsd:complexType name="GetUserRequestType">
  <xsd:all>
   <xsd:element name="Username" type="xsd:string" form="unqualified"/>
   <xsd:element name="Password" type="xsd:string" form="unqualified"/>
  </xsd:all>
 </xsd:complexType>
 <xsd:complexType name="GetUserResponseType">
  <xsd:all>
   <xsd:element name="userDetails" type="xsd:string" form="unqualified"/>
  </xsd:all>
 </xsd:complexType>
 <xsd:element name="GetUser" type="tns:GetUserRequestType"/>
 <xsd:element name="GetUserResponse" type="tns:GetUserResponseType"/>
</xsd:schema>
</types>
<message name="GetUserRequest">
  <part name="parameters" element="tns:GetUser"/></message>
<message name="GetUserResponse">
  <part name="parameters" element="tns:GetUserResponse"/></message>
<portType name="PsocialPortType">
  <operation name="GetUser">
    <input message="tns:GetUserRequest"/>
    <output message="tns:GetUserResponse"/>
  </operation>
</portType>
<binding name="PsocialBinding" type="tns:PsocialPortType">
  <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="GetUser">
    <soap:operation soapAction="urn:wwservice#GetUser" style="document"/>
    <input><soap:body use="literal" namespace="urn:wwservice"/></input>
    <output><soap:body use="literal" namespace="urn:wwservice"/></output>
  </operation>
</binding>
<service name="Psocial">
  <port name="PsocialPort" binding="tns:PsocialBinding">
    <soap:address location="http://example.com/webservice/wwservice.php"/>
  </port>
</service>
</definitions>

请让我知道我哪里出错了

我正在使用它来创建 WSDL

$server = new soap_server();
    // Changed for coupons data start
    $server->soap_defencoding = 'UTF-8';
    $server->decode_utf8 = false;
    // Changed for coupons data end

    //$server->configureWSDL('m-way', 'urn:wwservice');
    $server->configureWSDL('Psocial', 'urn:wwservice',false,'document');


    // New function for spiff
    $server->register("GetUser", 
    array('Username'=>'xsd:string','Password'=>'xsd:string'),
    array('userDetails'=>'xsd:string'),
    'urn:wwservice',
    'urn:wwservice#GetUser', 'document', 'literal'
    );



    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)? $HTTP_RAW_POST_DATA : file_get_contents('php://input');
    $server->service($HTTP_RAW_POST_DATA);
4

1 回答 1

2

问题是您获得的 SOAP 响应与 WSDL 中的描述不匹配,WSDL 具有elementFormDefault="qualified"模式,它表示子元素将在命名空间中,例如它说响应应该是

<GetUserResponse xmlns="urn:wwservice">
   <userDetails>Hello</userDetails>
</GetUserResponse>

但你得到的实际回应有

<GetUserResponse xmlns="urn:wwservice">
     <userDetails xmlns="">Successfully write a web service hurray</userDetails>
</GetUserResponse>

请注意 userDetails 元素的命名空间有何不同。您应该更新 WSDL 以说 elementForDefault="unqualified" 或更新 Web 服务以在 userDetails 元素上返回正确的名称空间。

于 2013-02-15T16:53:27.233 回答