简体   繁体   English

构建数组以使用复杂的wsdl-PHP

[英]Building array for consuming complex wsdl - PHP

I am having some issues, and yes, i am probably out of my league, but I do this for learning. 我遇到了一些问题,是的,我可能不在联盟范围内,但是我这样做是为了学习。

I am trying to consume a SOAP service, and i cannot, for the life of me build an array that the server accepts. 我正在尝试使用SOAP服务,但我终生无法建立服务器可以接受的数组。

WSDL is visible here: WSDL在这里可见:

http://metrolive.telenor.no/kapaks-facade-soap-web/services/KapaksFacade70SoapWrapper/wsdl http://metrolive.telenor.no/kapaks-facade-soap-web/services/KapaksFacade70SoapWrapper/wsdl

I can do this and it works perfectly fine: 我可以做到这一点,并且效果很好:

 $tlf = new SoapVar(
     array(
    new SoapVar(
        array(
            'ns2:connectionNumber' => 12345678,
            'ns2:connectionNumberType' => "T",
            'ns2:requestedProduct' => "OA"
        ), SOAP_ENC_OBJECT, null, null, null, 'http://web.soap.v70.kapaks.facade.metro2.telenor.com'
    )
), SOAP_ENC_OBJECT, null, null, null, 'http://dto.common.v70.kapaks.facade.metro2.telenor.com'
 );

 $client = new SoapClient($kapaks_wsdl, $wsdl_options);
 $result = $client->validateProductSoap($tlf);

This produces this xml: (From wireshark) 这将产生以下xml :(来自wireshark)

 <?xml version="1.0" encoding="UTF-8"?>
 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org /soap/envelope/" 
  xmlns:ns1="http://web.soap.v70.kapaks.facade.metro2.telenor.com"
      xmlns:ns2="http://dto.common.v70.kapaks.facade.metro2.telenor.com">
 <SOAP-ENV:Header/><SOAP-ENV:Body><ns1:validateProductSoap><ns1:BOGUS> 
     <ns2:connectionNumber>12345678</ns2:connectionNumber> 
<ns2:connectionNumberType>T</ns2:connectionNumberType> 
<ns2:requestedProduct>OA</ns2:requestedProduct></ns1:BOGUS> 
</ns1:validateProductSoap></SOAP-ENV:Body></SOAP-ENV:Envelope>

But, i need to request properties from the "address" node(Is it node?). 但是,我需要从“地址”节点请求属性(是节点吗?)。 I can not figure out how to map this into the array, i have been at this for days... 我不知道如何将其映射到数组中,我已经待了好几天了...

This XML works in curl: (Straigt from SoaP-UI) 此XML可在curl中工作:(来自SoaP-UI的Straaigt)

  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 

  xmlns:web="http://web.soap.v70.kapaks.facade.metro2.telenor.com"  

   xmlns:dto="http://dto.common.v70.kapaks.facade.metro2.telenor.com">
   <soapenv:Header/>
   <soapenv:Body>
  <web:validateProductSoap>
     <web:arg_0_0>
        <dto:address>

           <dto:houseLetter>A</dto:houseLetter>
           <dto:houseNumber>12</dto:houseNumber>

           <dto:municipalityNumber>0000</dto:municipalityNumber>

           <dto:streetCodeType>V</dto:streetCodeType>
           <dto:streetName>Street</dto:streetName>
        </dto:address>



        <dto:requestedProduct>OA</dto:requestedProduct>
     </web:arg_0_0>
    </web:validateProductSoap>
   </soapenv:Body>
 </soapenv:Envelope>

The curl approach gives me an xml response, but i need the array/object that soapclient produces, to be able to pass it to the front-end view. curl方法给了我一个xml响应,但是我需要soapclient生成的数组/对象才能将其传递到前端视图。

How can i produce a soapclient request that will request what is inside the address tag? 我如何产生一个soapclient请求,该请求将请求地址标签中的内容? Or make an array/object that is identical to what soapclient delivers? 还是制作一个与soapclient提供的相同的数组/对象?

I made a workaround. 我做了一个解决方法。 At this point i don't care how its done, just that it is done. 在这一点上,我不在乎它是如何完成的,只是它已经完成了。 Still, if someone has the answer on how to do it the correct way, i would like to see it. 不过,如果有人对正确方法的答案,我希望看到它。

I am using nusoap thats is updated for newer php ( https://github.com/econea/nusoap ) , and i send raw xml with that. 我正在使用nusoap多数民众赞成在更新的php( https://github.com/econea/nusoap )更新,并且我发送原始xml。

    function adresse($kmune1,$street1,$hnum1,$hletter1)
                {
                    require '..\vendor\econea\nusoap\src\nusoap.php';



                    $endpoint = "http://user:pw@metrolive.telenor.no:80/kapaks-facade-soap-web/services/KapaksFacade70SoapWrapper";

                    $client2 = new nusoap_client($endpoint, false);
                    $client2->soap_defencoding = 'UTF-8';
                    $client2->decode_utf8 = false;

                    $XMLrequest = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://web.soap.v70.kapaks.facade.metro2.telenor.com" xmlns:dto="http://dto.common.v70.kapaks.facade.metro2.telenor.com">
                   <soapenv:Header/>
                   <soapenv:Body>
                      <web:validateProductSoap>
                         <web:arg_0_0>
                            <dto:address>

                               <dto:houseLetter>'.$hletter1.'</dto:houseLetter>
                               <dto:houseNumber>'.$hnum1.'</dto:houseNumber>

                               <dto:municipalityNumber>'.$kmune1.'</dto:municipalityNumber>

                               <dto:streetCodeType>V</dto:streetCodeType>
                               <dto:streetName>'.$street1.'</dto:streetName>
                            </dto:address>



                            <dto:requestedProduct>OA</dto:requestedProduct>
                         </web:arg_0_0>
                      </web:validateProductSoap>
                   </soapenv:Body>
                </soapenv:Envelope>';


                    $result = $client2->send($XMLrequest, $endpoint, null);




                    $result=json_decode(json_encode($result));
                    return $result;


                }

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

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