当我尝试调用用PHP Web服务编写的Web方法时,我在.NET项目中收到“SOAP-ERROR:Encoding:object has not'tirst_name'properties”错误消息。 Web方法返回PHP数组$result_data
。我已经在WSDL中为数组返回的字段添加了元素。因为我是PHP的新手,无法获得返回数组的结构。该阵列似乎有两个级别。
$result_data => array(array( "first_name"
"last_name")
array( "first_name"
"last_name")
array( "first_name"
"last_name")
)
这是我的WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://10.20.1.161/api/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://10.20.1.161/api/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema targetNamespace="http://10.20.1.161/api/soap/" elementFormDefault="qualified">
<s:import namespace="http://microsoft.com/wsdl/types/"/>
<s:element name="getUsers">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="message" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getUsersResponse">
<s:complexType>
<s:sequence>
<s:element name="getUsersArray" type="tns:getUsersArray"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="getUsersArray">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="User" nillable="true" type="tns:User" />
</s:sequence>
</s:complexType>
<s:complexType name="User">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="first_name" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="last_name" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="regular_time" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="regular_time_wage" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="regular_time_wage_with_burden" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="regular_time_hourly_rate" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="regular_time_hourly_rate_with_burden" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="gross_wage" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="gross_wage_with_burden" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="worked_time" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="worked_days" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="verified_time_sheet" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="verified_time_sheet_date" type="s:string"/>
<!-- <s:element minOccurs="1" maxOccurs="1" name="absence_policy-3" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="absence_policy-3_wage" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="absence_policy-3_wage_with_burden" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="absence_policy-3_hourly_rate" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="absence_policy-3_hourly_rate_with_burden" type="s:string"/>-->
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
<wsdl:message name="getUsersSoapIn">
<wsdl:part name="parameters" element="tns:getUsers"/>
</wsdl:message>
<wsdl:message name="getUsersSoapOut">
<wsdl:part name="parameters" element="tns:getUsersResponse"/>
</wsdl:message>
<wsdl:portType name="TestSoap">
<wsdl:operation name="getUsers">
<wsdl:documentation xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'>
Function ("getUsers")
</wsdl:documentation>
<wsdl:input message="tns:getUsersSoapIn"/>
<wsdl:output message="tns:getUsersSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="TestSoap12">
<wsdl:operation name="getUsers">
<wsdl:documentation xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'>
Function ("getUsers")
</wsdl:documentation>
<wsdl:input message="tns:getUsersSoapIn"/>
<wsdl:output message="tns:getUsersSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestSoap" type="tns:TestSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getUsers">
<soap:operation soapAction="http://10.20.1.161/api/soap/getUsers" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="TestSoap12" type="tns:TestSoap12">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getUsers">
<soap12:operation soapAction="http://test-uri/soap/export/getUsers" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TestService">
<wsdl:port name="TestPort" binding="tns:TestSoap">
<soap:address location="http://10.20.1.161/api/soap/server.php"/>
</wsdl:port>
<wsdl:port name="TestSoap12" binding="tns:TestSoap12">
<soap12:address location="http://10.20.1.161/api/soap/server.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
我返回代码的部分。
$getUsersArray = $result->getResultData();
return array("getUsersArray" => $getUsersArray);
请帮忙。
答案 0 :(得分:4)
first_name
属性在您的WSDL中被minOccurs="1"
标记为必需。如果未在SOAP调用中设置first_name
,则会发生此错误。将该参数添加到您的调用中,您应该停止收到此错误。