我正在尝试使用PHP Soap服务但是我似乎遇到了复杂/抽象类型的问题。
这是使用SOAP UI生成的SOAP调用: -
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:lin="http://llu.webservices.opalonline.co.uk/LineCharacteristicsWS">
<soapenv:Header/>
<soapenv:Body>
<lin:GetLineCharacteristics>
<lin:request>
<!--Optional:-->
<lin:UserCredentials>
<!--Optional:-->
<!--Optional:-->
<lin:Username>testUser</lin:Username>
<lin:Password>testPass</lin:Password><lin:AgentID>1234</lin:AgentID>
</lin:UserCredentials>
<lin:RequestDetails xsi:type="lin:TelephoneNumberRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<lin:TelephoneNumber>123456789</lin:TelephoneNumber>
</lin:RequestDetails>
<lin:UserConsent>Yes</lin:UserConsent>
<lin:ServiceType>MPF</lin:ServiceType>
</lin:request>
</lin:GetLineCharacteristics>
</soapenv:Body>
</soapenv:Envelope>
这是我的PHP代码: -
$call = new StdClass();
$call->request = new StdClass();
$call->request->UserConsent = "Yes";
$call->request->ServiceType = "MPF";
$call->request->UserCredentials = new StdClass();
$call->request->UserCredentials->Username="testUser";
$call->request->UserCredentials->Password="testPass";
$call->request->UserCredentials->AgentID=1234;
$call->request->RequestDetails = new StdClass();
$call->request->RequestDetails->TelephoneNumber = "123456789";
$url = "https://llu.webservices.opalonline.co.uk/LineCharacteristicsWSV6/LineCharacteristicsWS.asmx?wsdl";
$client = new SoapClient($url, array('trace' => 1, exceptions=> 1,'soap_version' => SOAP_1_1));
$result = $client->GetLineCharacteristics($call);
echo $client->__getLastRequest();
echo $client->__getLastResponse();
运行代码时,会生成以下错误: -
致命错误:未捕获的SoapFault异常:[soap:Client]服务器无法读取请求。 ---&GT; XML文档中存在错误(2,382)。 ---&GT;指定的类型是abstract:name ='RequestType',namespace ='http://llu.webservices.opalonline.co.uk/LineCharacteristicsWS',位于http://llu.webservices.opalonline.co.uk/LineCharacteristicsWS'>。在/Users/jamesormerod/NetBeansProjects/fpdfDev/TestClass.php:23
有人可以帮忙吗?
答案 0 :(得分:0)
为了能够使用正确的类型和命名空间发送格式良好的请求,必须使用命名为必需元素的类和将元素映射到类的类映射。 WsdlToPhp项目可以帮助您生成类和类图。您可以在wsdltophp.com使用该项目。
然后,如果您生成名为LineCharacteristics
的包,您将能够使用此示例代码发送请求:
$lineCharacteristicsServiceGet = new LineCharacteristicsServiceGet();
// sample call for LineCharacteristicsServiceGet::GetLineCharacteristics()
$details = new LineCharacteristicsStructTelephoneNumberRequest('+3363136363636');
$request = new LineCharacteristicsStructGetLineCharacteristicsRequest($details, LineCharacteristicsEnumUserConsentEnum::VALUE_YES, LineCharacteristicsEnumServiceTypeEnum::VALUE_MPF);
$userCredentials = new LineCharacteristicsStructCredentials(11111,'********','********');
$request->setUserCredentials($userCredentials);
$characteristics = new LineCharacteristicsStructGetLineCharacteristics($request);
$r = $lineCharacteristicsServiceGet->GetLineCharacteristics($characteristics);
echo implode("\r\n", array($lineCharacteristicsServiceGet->getLastRequestHeaders(),$lineCharacteristicsServiceGet->getLastRequest(),$lineCharacteristicsServiceGet->getLastResponseHeaders(),$lineCharacteristicsServiceGet->getLastResponse()));
if($r)
print_r($lineCharacteristicsServiceGet->getResult());
else
print_r($lineCharacteristicsServiceGet->getLastError());