嘿伙计们我刚刚开始学习肥皂,当我期望收到一个好的整数并且当我期望收到一个字符串或数组或json时,我遇到了一个问题,错误是:
SOAP-ERROR: Encoding: Violation of encoding rules
我已经看到了关于此的所有答案,但它并没有帮助我。任何想法是什么问题?
感谢您的任何建议。
我的代码是:
<?xml version='1.0' encoding='UTF-8' ?>
<definitions name='Names'
targetNamespace='http://localhost/soap'
xmlns:tns=' http://localhost/soap '
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>
<message name="getNamesRequest">
<part name="num" type="xsd:string"/>
</message>
<message name="getNamesResponse">
<part name="Result" type="xsd:string"/>
</message>
<portType name="NamesPortType">
<operation name="getNames">
<input message="tns:getNamesRequest"/>
<output message="tns:getNamesResponse"/>
</operation>
</portType>
<binding name="NamesBinding" type="tns:NamesPortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getNames" />
</binding>
<service name="NamesService">
<port name="NamesPort" binding="tns:NamesBinding" >
<soap:address
location="http://localhost/soap/server.php" />
</port>
</service>
</definitions>
server.php
<?php
function getNames($num)
{
$name = $num;
return $name;
}
ini_set('soap.wsdl_cache_enabled', '0');
$server = new SoapServer("http://localhost/soap/names.wsdl");
$server->addFunction("getNames");
$server->handle();
client.php
<?php
try {
$client = new SoapClient('http://localhost/soap/names.wsdl');
$result = $client->getNames('victor');
echo $result;
} catch (SoapFault $e) {
echo $e->getMessage();
}
答案 0 :(得分:1)
请使用UTF-8
编码初始化您的服务器和客户端:
$server = new SoapServer('http://localhost/soap/names.wsdl', array('encoding'=>'UTF-8'));
$client = new SoapClient('http://localhost/soap/names.wsdl', array('encoding'=>'UTF-8'));