我有WCF SOAP服务。当.NET应用程序使用此服务时,一切正常。当我从PHP SoapClient使用此服务时,所有返回的值都被解释为字符串。类型在WSDL中定义。它完全忽略了它们。
我的回答是:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<EmployeeCountResponse xmlns="some namespace">
<EmployeeCountResult>569</EmployeeCountResult>
</EmployeeCountResponse>
</s:Body>
</s:Envelope>
我想象(注意xsi:type="xsd:int"
):
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<EmployeeCountResponse xmlns="some namespace">
<EmployeeCountResult xsi:type="xsd:int">569</EmployeeCountResult>
</EmployeeCountResponse>
</s:Body>
</s:Envelope>
在WSDL中有:
<xs:element name="EmployeeCountResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="EmployeeCountResult" nillable="true" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
当我在SoapUI中生成请求时,没有在元素上定义的xsi:type。有没有办法将元素添加到元素,或强制其他客户从?singlewsdl
读取此信息?
PHP代码:
$client = new SoapClient('someurl?singlewsdl',
array(
"stream_context" =>
stream_context_create(array("http"=>array(
"header"=> "ApiKey: somekey"
))),
'soap_version' => SOAP_1_1,
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => true,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
"trace" => true
)
);
try
{
$params = ['someparam' => 'somevalue'];
$resp = $client->employeeCount($params);
}
catch (SoapFault $exception)
{
echo($exception->getCode());
}
PHP将returedd int视为字符串,当WCF使用faultcode抛出异常时,PHP无法读取它,$exception->getCode()
返回'0'。