PHP客户端肥皂请求。如何使用继承的对象容器格式化请求数组

时间:2013-09-07 10:12:02

标签: php soap wsdl request

我正在使用PHP(SoapClient类)创建soap请求,但坚持寻找解决方案如何创建Person对象并将其添加到InsuredObjects列表。 Person继承了InsuredObject。

原始WSDL方案:

<VoyageRequestOfCalculateArgs>
  <MethodName>Calculate</MethodName>
  <Password>0000000000000</Password>
  <RequestData>
    <a:AgentId>9999</a:AgentId>
    <a:SessionKey>999999999999999999</a:SessionKey>
    <a:Contract i:type="b:Voyage">
      <startDate>2013-09-14T23:59:59+02:00</startDate>
      <endDate>2013-09-14T23:59:59+02:00</endDate>
      <b:type>Individual</b:type>
      <b:variant>Standard</b:variant>
      <insuredObjects>
        <InsuredObject i:type="b:Person">
        <b:address i:nil="true"/>
        <b:isOwner>false</b:isOwner>
        <b:ageGroup>AdultBetween4And64</b:ageGroup>
        <b:birthDate>0001-01-01T00:00:00</b:birthDate>
        <b:firstName i:nil="true"/>
        <b:idNumber i:nil="true"/>
        ...
        <errors/>
        <Risks>
         <Risk i:type="c:RiskAssistance">
            <basicRate>0</basicRate>
            ...
            <c:type>LCVASS</c:type>
         </Risk>
      </Risks>
   </InsuredObject>
  </insuredObjects>
</Contract>

...

这是我的请求数组:

$request = array(
                'request' => array(
                    "MethodName" => "Calculate",
                    "RequestData" => array(
                        'AgentId' => $this->config['username'],
                        'SessionKey' => $sessionKey,
                        'Contract' => array(
                            'startDate' => $startDate,
                            'endDate' => $endDate,
                            'type' => 'Individual',
                            'variant' => 'Standard',
                            'country' => array(
                                ...
                            ),
                            'insuredObjects' => array(
                             //-----------------------------------
                             //Here should be added person object.
                             //-----------------------------------
                                array(
                                    'errors' => '',
                                    'risks' => array(
                                        'type' => 'LCVKLS'
                                    ),
                                    'ageGroup' => 'AdultBetween4And64',
                                    'isForeigner' => false,
                                    ...
                                )
                            )
                        )
                    )
                )
            );

$result = $this->client->Calculate($request);

我的request($this->client->__getLastRequest())看起来像:     ...

<SOAP-ENV:Body>
    <ns5:Calculate>
        <ns5:request>
            <ns1:MethodName>Calculate</ns1:MethodName>
            <ns1:RequestData>
                <ns2:AgentId>9999</ns2:AgentId>
                <ns2:SessionKey>999999999999999999</ns2:SessionKey>
                <ns2:Contract>
                    <ns3:endDate>2013-09-19</ns3:endDate>
                    <ns3:insuredObjects>
                        <ns3:InsuredObject>
                            <ns3:errors/>
                            <ns3:risks/>
                        </ns3:InsuredObject>
                    </ns3:insuredObjects>
                    <ns3:startDate>2013-09-07</ns3:startDate>
                    <ns4:country>
                        <ns4:Code>EU</ns4:Code>
                        <ns4:Id>132</ns4:Id>
                        <ns4:IsVoyage30Range>true</ns4:IsVoyage30Range>
                        <ns4:Name>Europa</ns4:Name>
                    </ns4:country>
                    <ns4:type>Individual</ns4:type>
                    <ns4:variant>Standard</ns4:variant>
                </ns2:Contract>
            </ns1:RequestData>
        </ns5:request>
    </ns5:Calculate>
</SOAP-ENV:Body>

...

回复错误:

Unable to cast object of type 'Company.Common.BusinessObjects.InsuredObject' to type 'Company.VoyageService.BusinessObjects.Person'.

将属性传递给'risks' => 'type' => 'LCVKLS'

时遇到同样的问题

我希望你能帮助我找到问题。

0 个答案:

没有答案