SOAP-错误:编码:违反编码规则?
我正在尝试使用 Yii 提供网络服务。自动生成的 wsdl 如下。我可以从命令行成功使用 Web 服务,但通过 Web 浏览器,我发现
SOAP-ERROR: Encoding: Violation of encoding rules
我是 SOAP 新手,所以我不确定如何调试问题。这是我用来使用 Web 服务的 PHP 代码:
<?php
$client=new SoapClient('{url omitted for security}',
array('trace'=>1,'exceptions'=>1));
try {
$result = $client->getPerson(90043412);
var_dump($result);
} catch (SoapFault $fault) {
echo $fault->getMessage() . '<br />';
echo 'REQUEST <br />';
echo '<pre>';
echo $client->__getLastRequestHeaders();
echo $client->__getLastRequest();
echo '</pre>';
echo 'RESPONSE <br />';
echo '<pre>';
echo $client->__getLastResponseHeaders();
echo $client->__getLastResponse();
echo '</pre>';
echo 'TRACE <br />';
echo '<pre>';
var_dump($fault->getTrace());
echo '</pre>';
}
?>
这是 WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:PersonControllerwsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" name="PersonController" targetNamespace="urn:PersonControllerwsdl">
<wsdl:types>
<xsd:schema targetNamespace="urn:PersonControllerwsdl">
<xsd:complexType name="Person">
<xsd:all>
<xsd:element name="PIDM" type="xsd:integer"/>
<xsd:element name="FirstName" type="xsd:string"/>
<xsd:element name="MiddleName" type="xsd:string"/>
<xsd:element name="LastName" type="xsd:string"/>
<xsd:element name="PrefFirstName" type="xsd:string"/>
<xsd:element name="CPOBox" type="xsd:string"/>
<xsd:element name="Classification" type="xsd:string"/>
<xsd:element name="Email" type="xsd:string"/>
<xsd:element name="PhotoFile" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getPersonRequest">
<wsdl:part name="PIDM" type="xsd:int"/>
</wsdl:message>
<wsdl:message name="getPersonResponse">
<wsdl:part name="return" type="tns:Person"/>
</wsdl:message>
<wsdl:portType name="PersonControllerPortType">
<wsdl:operation name="getPerson">
<wsdl:documentation></wsdl:documentation>
<wsdl:input message="tns:getPersonRequest"/>
<wsdl:output message="tns:getPersonResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="PersonControllerBinding" type="tns:PersonControllerPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getPerson">
<soap:operation soapAction="urn:PersonControllerwsdl#getPerson" style="rpc"/>
<wsdl:input>
<soap:body use="encoded" namespace="urn:PersonControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</wsdl:input>
<wsdl:output>
<soap:body use="encoded" namespace="urn:PersonControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="PersonControllerService">
<wsdl:port name="PersonControllerPort" binding="tns:PersonControllerBinding">
<soap:address location="https://localhost/whoswho/person/service?ws=1"/>
</wsdl:port>
</wsdl:service>
</definitions>
I am trying to use Yii to provide a web service. The auto-generated wsdl is below. I can successfully consume the web service from the command line, but through a web browser, I get
SOAP-ERROR: Encoding: Violation of encoding rules
I am new to SOAP, so I am not sure how to debug the problem. Here is the PHP code I am using to consume the web service:
<?php
$client=new SoapClient('{url omitted for security}',
array('trace'=>1,'exceptions'=>1));
try {
$result = $client->getPerson(90043412);
var_dump($result);
} catch (SoapFault $fault) {
echo $fault->getMessage() . '<br />';
echo 'REQUEST <br />';
echo '<pre>';
echo $client->__getLastRequestHeaders();
echo $client->__getLastRequest();
echo '</pre>';
echo 'RESPONSE <br />';
echo '<pre>';
echo $client->__getLastResponseHeaders();
echo $client->__getLastResponse();
echo '</pre>';
echo 'TRACE <br />';
echo '<pre>';
var_dump($fault->getTrace());
echo '</pre>';
}
?>
Here is the WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:PersonControllerwsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" name="PersonController" targetNamespace="urn:PersonControllerwsdl">
<wsdl:types>
<xsd:schema targetNamespace="urn:PersonControllerwsdl">
<xsd:complexType name="Person">
<xsd:all>
<xsd:element name="PIDM" type="xsd:integer"/>
<xsd:element name="FirstName" type="xsd:string"/>
<xsd:element name="MiddleName" type="xsd:string"/>
<xsd:element name="LastName" type="xsd:string"/>
<xsd:element name="PrefFirstName" type="xsd:string"/>
<xsd:element name="CPOBox" type="xsd:string"/>
<xsd:element name="Classification" type="xsd:string"/>
<xsd:element name="Email" type="xsd:string"/>
<xsd:element name="PhotoFile" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getPersonRequest">
<wsdl:part name="PIDM" type="xsd:int"/>
</wsdl:message>
<wsdl:message name="getPersonResponse">
<wsdl:part name="return" type="tns:Person"/>
</wsdl:message>
<wsdl:portType name="PersonControllerPortType">
<wsdl:operation name="getPerson">
<wsdl:documentation></wsdl:documentation>
<wsdl:input message="tns:getPersonRequest"/>
<wsdl:output message="tns:getPersonResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="PersonControllerBinding" type="tns:PersonControllerPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getPerson">
<soap:operation soapAction="urn:PersonControllerwsdl#getPerson" style="rpc"/>
<wsdl:input>
<soap:body use="encoded" namespace="urn:PersonControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</wsdl:input>
<wsdl:output>
<soap:body use="encoded" namespace="urn:PersonControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="PersonControllerService">
<wsdl:port name="PersonControllerPort" binding="tns:PersonControllerBinding">
<soap:address location="https://localhost/whoswho/person/service?ws=1"/>
</wsdl:port>
</wsdl:service>
</definitions>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
SOAP 请求的格式可能不正确。我一直在使用 SoapUI,默认情况下所有参数都设置为“?”最初,如果您发出此请求,PHP 将失败并以您报告的错误消息进行响应。你无法捕获这个,因为没有抛出异常,这是因为这是一个致命错误。
您可以使用 set_error_handler() 函数针对这种情况设置自己的错误处理程序 http ://php.net/manual/en/function.set-error-handler.php
It is possible that the SOAP request is incorrectly formatted. I've been using SoapUI and by default all the parameters are set to '?' initially, if you make this request PHP will fail and respond with the error message you have reported. You cannot catch this, because no exception is thrown, this is because it is a fatal error.
You can set your own error handler for this situation using the set_error_handler() function http://php.net/manual/en/function.set-error-handler.php
我正在努力将我的 PHP 版本更新到 5.6.26,并且在我的 Web 服务调用中弹出此错误。一段时间后,我发现这个问题可以通过在 PHP.ini 文件中注释这一行来解决:
查看文档,此版本中不推荐使用此选项。
我希望此评论可以为某人节省时间。
I was working to update my PHP version to 5.6.26 and this error pop-up on my web services calls. After a while, I found the issue could be fixed commenting in the PHP.ini file this line:
Reviewing the documentation, this option is deprecated in this version.
I hope this comment save time to someone.
如果我将消费脚本托管在与托管 Web 服务的服务器不同的服务器上,则它可以正常运行。由于 Web 服务是为机器间通信而设计的,而不是机器自言自语,因此这似乎是一个足够的解决方案。
If I host the consume script on a different server than the one hosting the web service, it functions properly. Since web services are designed for machine-machine communication more than a machine talking to itself, this seems like an adequate solution.
我知道这是一个旧线程,但是如果您像我试图解决这个问题一样遇到它,您可以尝试将soap:address 设置为 http://127.0.0.1 而不是 http://localhost。我遇到过一些其他论坛,这对我有帮助。
I know this is an old thread, but if you come across it as I did trying to figure out this problem, you might try setting the soap:address to http://127.0.0.1 instead of http://localhost. I've run into a few other forums where this helped.