简体   繁体   English

PHP Soap复杂数据类型?

[英]PHP Soap Complex Data Type?

I am trying to consume a PHP Soap service however I seem to have having trouble with a complex/abstract type. 我正在尝试使用PHP Soap服务,但是我似乎在使用复杂/抽象类型时遇到了麻烦。

This is the SOAP call generated using SOAP UI :- 这是使用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>

Here is my PHP code :- 这是我的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();

When I run the code, the following error is generated :- 当我运行代码时,会产生以下错误:-

Fatal error: Uncaught SoapFault exception: [soap:Client] Server was unable to read request. 致命错误:未捕获的SoapFault异常:[soap:Client]服务器无法读取请求。 ---> There is an error in XML document (2, 382). ---> XML文档(2,382)中有错误。 ---> The specified type is abstract: name='RequestType', namespace=' http://llu.webservices.opalonline.co.uk/LineCharacteristicsWS ', at http://llu.webservices.opalonline.co.uk/LineCharacteristicsWS'>. --->指定的类型是抽象的:name ='RequestType',namespace =' http://llu.webservices.opalonline.co.uk/LineCharacteristicsWS ',位于http://llu.webservices.opalonline.co.uk / LineCharacteristicsWS'>。 in /Users/jamesormerod/NetBeansProjects/fpdfDev/TestClass.php:23 在/Users/jamesormerod/NetBeansProjects/fpdfDev/TestClass.php:23中

Can anyone help? 有人可以帮忙吗?

To be able to send the request well formed with correct type and namespace, you must use both classes named as the required elements and a classmap that maps the elements to the classes. 为了能够以正确的类型和名称空间发送格式正确的请求,您必须同时使用名为必需元素的类和将元素映射到类的类映射。 The WsdlToPhp project can help you generate the classes and the classmap. WsdlToPhp项目可以帮助您生成类和类映射。 You can use the project at wsdltophp.com . 您可以在wsdltophp.com上使用该项目。

Then if for example you generate the package with the name LineCharacteristics , you'll be able to send the request using this sample code: 然后,例如,如果您生成名称为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());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM