1. <legend id='V6Bhd'><style id='V6Bhd'><dir id='V6Bhd'><q id='V6Bhd'></q></dir></style></legend>
          <bdo id='V6Bhd'></bdo><ul id='V6Bhd'></ul>

      2. <small id='V6Bhd'></small><noframes id='V6Bhd'>

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

        如何从此xml在php中生成soap请求?

        时间:2023-05-22
      4. <legend id='2NmUI'><style id='2NmUI'><dir id='2NmUI'><q id='2NmUI'></q></dir></style></legend>

        <small id='2NmUI'></small><noframes id='2NmUI'>

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

                  本文介绍了如何从此xml在php中生成soap请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我厌倦了尝试使用 SOAP 发送请求.这是我的 xml

                  I'm tired of trying to send a request with SOAP. this is my xml

                  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:bpf="http://schemas.datacontract.org/2004/07/Bpf.Security.Common" xmlns:bpf1="http://schemas.datacontract.org/2004/07/Bpf.Security.Authentication.Common">
                           <soapenv:Header>
                   <InfoTag xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.w3.org/BaufestProductivityFramework">
                    <ClientIp xmlns="http://schemas.datacontract.org/2004/07/Bpf.Common.Service">200.125.145.10</ClientIp> 
                    <CompanyId xmlns="http://schemas.datacontract.org/2004/07/Bpf.Common.Service">1</CompanyId>
                    <UserName xmlns="http://schemas.datacontract.org/2004/07/Bpf.Common.Service">someUser</UserName> 
                    </InfoTag>
                          </soapenv:Header>
                             <soapenv:Body>
                                <tem:LogIn>         
                                  <tem:token>
                                      <bpf:type>
                                         <bpf1:Description>someDesc</bpf1:Description>
                                         <bpf1:Id>1</bpf1:Id>
                                         <bpf1:Name>someDesc</bpf1:Name>
                                      </bpf:type>
                                      <bpf:password>somePass</bpf:password>
                                      <bpf:userName>someUser</bpf:userName>
                                  </tem:token>
                                </tem:LogIn>
                             </soapenv:Body>
                          </soapenv:Envelope>
                  

                  这个函数发送带有命名空间的头部,但不止一个...我必须把它们全部发送?

                  this function send the header with a namespace, but there are more than one... I have to send them all?

                   private function __getHeaders() {
                              $ns = 'http://schemas.xmlsoap.org/soap/envelope/'; //Namespace of the WS. 
                              $ip = $_SERVER['REMOTE_ADDR'];
                      //Body of the Soap Header. 
                              $headerbody = array('ClientIp' => $ip,
                                                  'CompanyId' => 1, 
                                                  'UserName' => 'someUser'
                                                  );
                  
                      //Create Soap Header.        
                              $header = new SOAPHeader($ns, 'InfoTag', $headerbody);
                              return $header;
                          }
                  
                      public function prepareWs(){
                      $wsdl="the web service";
                             $client = new SoapClient($wsdl, array('trace' => true));
                      //Set the Headers of Soap Client. 
                             $header = $this->__getHeaders();
                             $client->__setSoapHeaders($header);
                  

                  我尝试发送此正文,我检查了带有soap错误的异常,但该消息仅返回错误请求NULL NULL NULL".

                  I try to send this body, I inspected exception with soap fault but the message only returns "bad request NULL NULL NULL".

                  $params = new stdClass();  
                        $params = new SoapVar("<tem:token>
                          <bpf:type xmlns:bpf="http://schemas.datacontract.org/2004/07/Bpf.Security.Common">
                             <bpf1:Description xmlns:bpf1="http://schemas.datacontract.org/2004/07/Bpf.Security.Authentication.Common">someDesc</bpf1:Description>
                             <bpf1:Id xmlns:bpf1="http://schemas.datacontract.org/2004/07/Bpf.Security.Authentication.Common">1</bpf1:Id>
                             <bpf1:Name xmlns:bpf1="http://schemas.datacontract.org/2004/07/Bpf.Security.Authentication.Common">someName</bpf1:Name>
                          </bpf:type>
                          <bpf:password xmlns:bpf="http://schemas.datacontract.org/2004/07/Bpf.Security.Common">somePass</bpf:password>
                          <bpf:userName xmlns:bpf="http://schemas.datacontract.org/2004/07/Bpf.Security.Common">someUser</bpf:userName>
                      </tem:token>", XSD_ANYXML);
                  
                         $response = $client->Login($params);
                  
                  }
                  

                  使用 CURL 我可以发送这个 XML 并收到 XML 响应,但是使用 SOAPClient 我不能发送这个请求.

                  With CURL I can send this XML and recieved the XML response too, but with SOAPClient I can't send this request.

                  希望有人能帮助我,谢谢.

                  I hope someone can help me, thanks.

                  这是我可以用 firebug 看到的代码,我唯一得到的是错误的请求".当我使用 __getLastRequest() 我看到同样的......我猜不应该正确发送标头,但是 __setSoapHeaders 函数返回 true.这是输出:

                  This is the code I can see with firebug, the only thing I get is "bad request". When I use __getLastRequest() I see the same... I guess the headers should not be sent correctly, however the __setSoapHeaders function returns true. This is the output:

                  <soap-env:envelope xmlns:ns1="http://tempuri.org/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
                  <soap-env:header>
                  <soap-env:contextinformation>
                  <item>
                  <key>ClientIp</key>
                  <value>127.0.0.1</value>
                  </item>
                  <item>
                  <key>CompanyId</key>
                  <value>1</value>
                  </item>
                  <item>
                  <key>UserName</key>
                  <value>someUser</value>
                  </item>
                  </soap-env:contextinformation>
                  </soap-env:header>
                  <soap-env:body>
                  <tem:login>
                  <tem:token>
                  <bpf:type>
                  <bpf1:description>someDesc</bpf1:description>
                  <bpf1:id>1</bpf1:id>
                  <bpf1:name>someName</bpf1:name>
                  </bpf:type>
                  <bpf:password>somePass</bpf:password>
                  <bpf:username>someUser</bpf:username>
                  </tem:token>
                  </tem:login>
                  </soap-env:body>
                  </soap-env:envelope>
                  

                  推荐答案

                  SoapHeader 处理数组相当随意.如果您想使用数组,请考虑使用 ArrayObject 而不是原生结构.

                  SoapHeader treats arrays rather arbitrarily. If you ever want to use an array, consider using ArrayObject instead of the native construct.

                  但是,您根本不需要数组,因为您只是想在标题中构造单个元素.并且因为您的每个内部元素(例如 ClientIP)都有一个唯一的命名空间,所以您不能只传入一个基本对象.相反,您必须使用 SoapVar 类为每个元素指定一个特定的命名空间,这允许您将普通 PHP 数据包装在 SoapClient 可以的SOAP-ready"容器中理解和翻译.

                  However, you don't need an array at all since you're only trying to construct a single element in your header. And because each of your internal elements (eg. ClientIP) has a unique namespace, you can't just pass in a basic object. Instead, you have to specify a particular namespace for each element using the SoapVar class, which allows you to wrap normal PHP data in a "SOAP-ready" container that SoapClient can understand and translate.

                  $innerNS = "http://www.w3.org/BaufestProductivityFramework";
                  $outerNS = "http://schemas.datacontract.org/2004/07/Bpf.Common.Service";
                  
                  $tag = new stdClass();
                  $tag->ClientIP = new SoapVar("200.125.145.10", XSD_STRING, null, null, null, $innerNS);
                  $tag->CompanyId = new SoapVar(1, XSD_INT, null, null, null, $innerNS);
                  $tag->UserName = new SoapVar("someUser", XSD_STRING, null, null, null, $innerNS);
                  
                  $client->__setSoapHeaders(new SoapHeader($outerNS, 'InfoTag', $tag));
                  

                  最后,作为一项规则,不要手动编写 XML! 考虑像此处显示的标头代码那样重新编写 SOAP 主体代码.您应该能够专门处理 XML 的内容,而不是它的结构.

                  Finally, as a rule, don't manually write XML! Consider re-writing your SOAP body code like the header code shown here. You ought to be able to deal specifically with the content of the XML, not its structure.

                  这篇关于如何从此xml在php中生成soap请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:肥皂:信封 SOAP-ENV:信封 PHP 下一篇:PHP SoapClient 是否支持 HTTPS 连接

                  相关文章

                  最新文章

                  • <bdo id='pGrgt'></bdo><ul id='pGrgt'></ul>

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

                    <small id='pGrgt'></small><noframes id='pGrgt'>

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

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