<bdo id='cubHv'></bdo><ul id='cubHv'></ul>

    1. <tfoot id='cubHv'></tfoot>

    2. <i id='cubHv'><tr id='cubHv'><dt id='cubHv'><q id='cubHv'><span id='cubHv'><b id='cubHv'><form id='cubHv'><ins id='cubHv'></ins><ul id='cubHv'></ul><sub id='cubHv'></sub></form><legend id='cubHv'></legend><bdo id='cubHv'><pre id='cubHv'><center id='cubHv'></center></pre></bdo></b><th id='cubHv'></th></span></q></dt></tr></i><div id='cubHv'><tfoot id='cubHv'></tfoot><dl id='cubHv'><fieldset id='cubHv'></fieldset></dl></div>

      1. <small id='cubHv'></small><noframes id='cubHv'>

        <legend id='cubHv'><style id='cubHv'><dir id='cubHv'><q id='cubHv'></q></dir></style></legend>

        PHP SoapClient 和复杂的标头

        时间:2023-05-22

        1. <i id='HhBer'><tr id='HhBer'><dt id='HhBer'><q id='HhBer'><span id='HhBer'><b id='HhBer'><form id='HhBer'><ins id='HhBer'></ins><ul id='HhBer'></ul><sub id='HhBer'></sub></form><legend id='HhBer'></legend><bdo id='HhBer'><pre id='HhBer'><center id='HhBer'></center></pre></bdo></b><th id='HhBer'></th></span></q></dt></tr></i><div id='HhBer'><tfoot id='HhBer'></tfoot><dl id='HhBer'><fieldset id='HhBer'></fieldset></dl></div>

            <legend id='HhBer'><style id='HhBer'><dir id='HhBer'><q id='HhBer'></q></dir></style></legend>

            <tfoot id='HhBer'></tfoot>
            • <bdo id='HhBer'></bdo><ul id='HhBer'></ul>

                • <small id='HhBer'></small><noframes id='HhBer'>

                    <tbody id='HhBer'></tbody>
                  本文介绍了PHP SoapClient 和复杂的标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我已经尝试了一段时间,但我不知道如何将 PHP SoapCLient 与 WSDL 结合使用以形成复杂的标头(也就是说,比我能找到的任何教程都复杂).我需要发送的信封是这样的:

                  I have been trying for a while now, but I can't figure out how to use PHP SoapCLient in combination with a WSDL to form a complex header (that is, more complex than any tutorial I could find). The envelope that I need to send looks like this:

                  (001) <?xml version='1.0' encoding='UTF-8'?>
                  
                  (002) <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xlink="http://www.w3.org/1999/xlink">
                  
                  (003) <SOAP-ENV:Header>
                  
                  (004) <eb:MessageHeader xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" eb:version="2.0" SOAP-ENV:mustUnderstand="1">
                  
                  (005) <eb:From>
                  
                  (006) <eb:PartyId>webservices.example.com</eb:PartyId> 
                  
                  (007) </eb:From>
                  
                  (008) <eb:To>
                  
                  (009) <eb:PartyId>clientURL</eb:PartyId> 
                  
                  (010) </eb:To>
                  
                  (011) <eb:CPAId>IPCC</eb:CPAId> 
                  
                  (012) <eb:ConversationId>ABC123@clientURL.com</eb:ConversationId> 
                  
                  (013) <eb:Service eb:type="XML">Session</eb:Service> 
                  
                  (014) <eb:Action>SessionCreateRS</eb:Action> 
                  
                  (015) <eb:MessageData>
                  
                  (016) <eb:MessageId>mid:20030707-12545-1369@webservices.sabre.com</eb:MessageId> 
                  
                  (017) <eb:Timestamp>2001-02-15T11:25:12Z</eb:Timestamp> 
                  
                  (018) </eb:MessageData>
                  
                  (019) <RefToMessageId>mid:20001209-133003-2333@clientURL</RefToMessageId> 
                  
                  (020) </eb:MessageHeader>
                  
                  (021) <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
                  
                  (022) <wsse:BinarySecurityToken xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility" wsu:Id="SabreSecurityToken" valueType="String" EncodingType="wsse:Base64Binary">Shared/IDL:IceSess/SessMgr:1.0.IDL/Common/!ICESMS/RESC!ICESMSLB/RES.LB!-4954987477210575357!252506!0</wsse:BinarySecurityToken> 
                  
                  (023) </wsse:Security>
                  
                  (024) </SOAP-ENV:Header>
                  
                  (025) <SOAP-ENV:Body>
                  
                  (026) <eb:Manifest xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" eb:version="2.0">
                  
                  (027) <eb:Reference eb:id="SessionCreateRS" xlink:type="simple" xlink:href="cid:SessionCreateRS"
                  
                  (028) <eb:Description xml:lang="en-US">Response Message</eb:Description>"/>
                  
                  (029) </eb:Reference>
                  
                  (030) </eb:Manifest>
                  
                  (031) </SOAP-ENV:Body>
                  
                  (032) </SOAP-ENV:Envelope>
                  

                  我尝试使用 __setSoapHeaders() 和 SoapVar() 来实现它.虽然我无法获得正确的输出.从例子中我了解到使用类来填充 XML 中的参数会很好,所以我做了一个这样的类:

                  I tried to make it using __setSoapHeaders() and using SoapVar(). I can't get the right output though. From examples I learned it would be good to use a class to fill the parameters in the XML, so I made an class like this:

                  class EbXmlMessage{
                   public $From = array('PartyId' => 'www.example.com@example.com');
                   public $To = array('PartyId' => 'example.com');
                   public $CPAId = 'XXXX';
                   public $ConversationId = '12345@example.com';
                   public $Service = 'Session';
                   public $Action = 'SessionCreateRQ';
                   public $MessageData = array( 'MessageId' => "mid:12345@example.com",'Timestamp' => '2010-11-26T08:19:00Z');
                  }
                  

                  比我使用的:

                  $eb_params = new SoapVar($eb,SOAP_ENC_OBJECT);
                  $header =  new SoapHeader($ns,"header", $eb_params,true);
                  

                  但是该请求甚至没有看起来像必须的那样:

                  But the request does not even slightly begin to look like it has to:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.opentravel.org/OTA/2002/11" xmlns:ns2="https://cert.webservices.sabre.com/cert">
                   <SOAP-ENV:Header>
                    <ns2:header SOAP-ENV:mustUnderstand="1">
                     <From>
                      <item>
                       <key>PartyId</key>
                       <value>www.example.com@example.com</value>
                      </item>
                     </From>
                     <To>
                      <item>
                       <key>PartyId</key>
                       <value>webservices.sabre.com</value>
                      </item>
                     </To>
                     <CPAId>XXX</CPAId>
                     <ConversationId>12345@example.com</ConversationId>
                     <Service>Session</Service>
                     <Action>SessionCreateRQ</Action>
                     <MessageData>
                      <item>
                       <key>MessageId</key>
                       <value>mid:12345@www.example.com</value>
                      </item>
                      <item>
                       <key>Timestamp</key>
                       <value>2010-11-26T08:19:00Z</value>
                      </item>
                     </MessageData>
                    </ns2:header>
                   </SOAP-ENV:Header>
                   <SOAP-ENV:Body>
                    <ns1:SessionCreateRQ>
                     <ns1:POS>
                      <ns1:Source PseudoCityCode="XXXX"/>
                     </ns1:POS>
                    </ns1:SessionCreateRQ>
                    <param1/>
                   </SOAP-ENV:Body>
                  </SOAP-ENV:Envelope
                  

                  目前的主要问题是在正确的位置获取 XML 中正确的标签,我不知道如何在标签中获取eb:"和wsse:"命名空间.我希望使用 SoapClientI() 类,但我不确定它是否可以处理像我需要的那样更复杂的 XML,如果不能,也许我应该使用 Curl 或类似的东西并将 XML 视为字符串?

                  The main problems so far are getting the right tags in the XML on the right place, and I don't know how I can get "eb:" and "wsse:" namespace in the tags. I am hoping to use the SoapClientI() class but I'm not sure if it can handle a more complex XML like the one I need, if not maybe I should use Curl or something similar and just treat the XML as a string?

                  推荐答案

                  我在实施 wsse 时也遇到了这个问题.这是我的方法.是的,这是特定于 wsse 的;但是,它也应该适用于您的上下文.请特别注意在对 new SoapHeader() 的调用中如何使用 'wsse' 命名空间参数.只需将其替换为 'eb' 即可.

                  I had issues with this as well when implementing wsse. Here was my approach. Yes, this is quite wsse-specific; however, it should work in your context as well. Note especially how there's the 'wsse' namespace parameter in the call to new SoapHeader(). Just replace that with 'eb' for your case.

                  $header_part = '
                      <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext" SOAP-ENV:mustUnderstand="1">
                          <wsse:UsernameToken>
                              <wsse:Username>'."USERNAME".'</wsse:Username>
                              <wsse:Password>'."PASSWORD".'</wsse:Password>
                          </wsse:UsernameToken>
                      </wsse:Security>
                  ';
                  $soap_var_header = new SoapVar( $header_part, XSD_ANYXML, null, null, null );
                  $soap_header = new SoapHeader( 'http://your-target-service.com', 'wsse', $soap_var_header );
                  $soap_client->__setSoapHeaders($soap_header);
                  

                  另一种解决方案是在对 SoapClient 进行子类化后处理 XML,但我只会将其作为最后的手段.

                  Another solution is to mangle the XML after subclassing the SoapClient, but I'd only do this as a last resort.

                  class My_SoapClient extends SoapClient {
                     protected $_response = null;
                     public function __doRequest( $request, $location, $action, $version, $one_way=null ) {
                        // insert big bad mangling code here
                        $this->_response = parent::__doRequest( $this->_request, $location, $action, $version, $one_way );
                        return $this->_response;
                     }
                  }
                  

                  这篇关于PHP SoapClient 和复杂的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 cURL 执行 SOAP 下一篇:无法理解 PHP 中的 SOAP

                  相关文章

                  最新文章

                    1. <i id='7Bsa3'><tr id='7Bsa3'><dt id='7Bsa3'><q id='7Bsa3'><span id='7Bsa3'><b id='7Bsa3'><form id='7Bsa3'><ins id='7Bsa3'></ins><ul id='7Bsa3'></ul><sub id='7Bsa3'></sub></form><legend id='7Bsa3'></legend><bdo id='7Bsa3'><pre id='7Bsa3'><center id='7Bsa3'></center></pre></bdo></b><th id='7Bsa3'></th></span></q></dt></tr></i><div id='7Bsa3'><tfoot id='7Bsa3'></tfoot><dl id='7Bsa3'><fieldset id='7Bsa3'></fieldset></dl></div>

                      <small id='7Bsa3'></small><noframes id='7Bsa3'>

                      • <bdo id='7Bsa3'></bdo><ul id='7Bsa3'></ul>
                      <tfoot id='7Bsa3'></tfoot>
                    2. <legend id='7Bsa3'><style id='7Bsa3'><dir id='7Bsa3'><q id='7Bsa3'></q></dir></style></legend>