伙计们,我被困住了,在过去的几个小时里,我的头撞了桌子.
我正在尝试使用一个服务,并且我有8个其他函数,我称之为本质上几乎是IDENTICAL,但是这个函数会导致'SOAP-ERROR:Encoding:违反编码规则'错误.
继承函数调用(为安全起见省略了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;
}
}
Run Code Online (Sandbox Code Playgroud)
好的,这个函数,连接到web服务,所需的元素是:用户名,密码,prod,mdn,我提供的所有4个作为$ params数组的一部分.用户名/传递是先前定义的,并且工作正常,因为其他8个函数使用Web服务没有任何问题.
$ data []数组(我传递给函数)包含:$ data ['productid'] $ data ['mdn']没有使用其他内容.
我正进入(状态
SOAP-ERROR: Encoding: Violation of encoding rules
Run Code Online (Sandbox Code Playgroud)
由于一些无法解释的原因,谷歌搜索这个错误让我无处可去.其他人遇到这个?运行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;
}
Run Code Online (Sandbox Code Playgroud)
这是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>
Run Code Online (Sandbox Code Playgroud)
Hen*_*pel 16
看起来你在某个地方有类型不匹配,无论是在组装你的请求时(其中一个参数不是string类型),或者服务器返回的不是int(违反了WSDL响应定义,从而导致客户端考虑响应无效,因为它需要其他东西).
一些额外的意见/问题:
$client->__soapCall("CanLoadProduct", $params)
代替$client->CanLoadProduct($username, $password, etc.)
?(第一个版本是较低级别的变体,旨在用于非WSDL方案.第二个版本可能会为您提供更详细的错误/异常)小智 6
我有同样的问题.
在soapUI首选项中,我选中了首选项→编辑器设置→验证响应选项,我收到了以下信息:
第3027行:十进制值无效:意外字符'44'.
这解决了我的问题.字段包含错误的类型值.
如果将 PHP 版本升级到 7.3 或更高版本,以前的 WSDL 缓存可能会停止工作。
默认安装目录为/tmp
,禁用缓存或删除 wsdl* 缓存文件应该可以解决该问题。我建议清除缓存,否则您的服务器每次都会提取 WSDL(这可能是不可取的)。