【发布时间】:2010-11-21 12:32:21
【问题描述】:
伙计们,我被困住了,在过去的几个小时里,我的头从桌子上撞了下来。
我正在尝试使用一项服务,并且我调用了 8 个其他函数,这些函数在本质上与这个函数几乎相同,但是这个函数会导致“SOAP-ERROR: Encoding: Violation of encoding rules”错误.
以下是函数调用(出于安全考虑,省略了wsdl):
function CanLoadProduct($data){
$client = new SoapClient('wsdl-url');
$params = array('username' => $this->username,
'password' => $this->password,
'prod' => $data['productid'],
'mdn' => $data['mdn']);
try {
$reply = $client->__soapCall("CanLoadProduct", $params);
} catch (Exception $e) {
echo 'Error: ', $e->getMessage(), "\n";
print_r($params);
die();
}
if( $reply['result'] == 1 ){
return TRUE; // 1 = true
} else {
return FALSE;
}
}
好的,这个函数,连接到一个网络服务,需要的元素是: 用户名、密码、prod、mdn,所有这 4 个都是我作为 $params 数组的一部分提供的。用户名/密码已在前面定义,并且工作正常,因为其他 8 个函数使用 Web 服务没有任何问题。
$data[] 数组(我传递给函数)包含: $data['productid'] $数据['mdn'] 没有使用其他任何东西。
我来了
SOAP-ERROR: Encoding: Violation of encoding rules
出于某种无法解释的原因,谷歌搜索这个错误让我无处可去。还有其他人遇到这个吗?运行 PHP 5.2.9-2。奇怪的是,这与这个 100% 有效的功能相同:
function GetPIN($productid){
$client = new SoapClient('wsdl-url');
$params = array('username' => $this->username,
'password' => $this->password,
'prod' => $productid);
try {
$reply = $client->__soapCall("GetPIN", $params);
} catch (Exception $e) {
echo 'Error: ', $e->getMessage(), "\n";
die();
}
return $reply;
}
这是 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="ready:test" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="ready:test">
<types>
<xsd:schema targetNamespace="ready:test"
>
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
</xsd:schema>
</types>
<message name="CanLoadProductRequest">
<part name="username" type="xsd:string" />
<part name="password" type="xsd:string" />
<part name="prod" type="xsd:string" />
<part name="mdn" type="xsd:string" />
<part name="esn" type="xsd:string" /></message>
<message name="CanLoadProductResponse">
<part name="result" type="xsd:int" /></message>
<portType name="CanLoadProductPortType">
<operation name="CanLoadProduct">
<input message="tns:CanLoadProductRequest"/>
<output message="tns:CanLoadProductResponse"/>
</operation>
</portType>
<binding name="CanLoadProductBinding" type="tns:CanLoadProductPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="CanLoadProduct">
<soap:operation soapAction="{url-removed}" style="rpc"/>
<input>
<soap:body use="encoded" namespace=""
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace=""
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="CanLoadProduct">
<port name="CanLoadProductPort" binding="tns:CanLoadProductBinding">
<soap:address location="{url-removed}"/>
</port>
</service>
</definitions>
【问题讨论】:
-
如果这是一个 .NET 客户端,我会尝试将“prod”和“mdn”硬编码为已知良好的值,然后看看会发生什么。如果可行,我会一次删除一个硬代码,看看哪个是问题所在。然后我会查看失败的值,看看它是否有什么特别之处。
-
这也是我的第一个想法。
-
我尝试对其进行硬编码,但得到相同的结果,非常奇怪。我不知道任何其他解决此问题的方法。
-
有趣。我认为接下来我想做的是查看 WSDL,然后尝试使用不同的语言(如 Java 或 C#)创建类似的客户端。事实上,在充分尊重“脚本”语言的情况下,我会确保另一种语言具有更多工具支持等。我只会尝试实现一个调用。看看它是否有效会很有趣。
-
我已经包含了 WSDL,抱歉应该早点完成。