• <legend id='iiZl4'><style id='iiZl4'><dir id='iiZl4'><q id='iiZl4'></q></dir></style></legend>

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

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

      <tfoot id='iiZl4'></tfoot>

        • <bdo id='iiZl4'></bdo><ul id='iiZl4'></ul>
      1. 使用 PHP 和 XML 主体创建 SOAP 调用

        时间:2023-05-22
            <bdo id='3tiIs'></bdo><ul id='3tiIs'></ul>

            1. <tfoot id='3tiIs'></tfoot>
            2. <legend id='3tiIs'><style id='3tiIs'><dir id='3tiIs'><q id='3tiIs'></q></dir></style></legend>

              <small id='3tiIs'></small><noframes id='3tiIs'>

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

                • 本文介绍了使用 PHP 和 XML 主体创建 SOAP 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试使用 PHP 调用 SOAP 方法.

                  I'm trying to call a SOAP method using PHP.

                  这是我得到的代码:

                  $data = array('Acquirer' =>
                    array(
                      'Id' => 'MyId',
                      'UserId' => 'MyUserId',
                      'Password' => 'MyPassword'
                    ));
                  $method = 'Echo';
                  $client = new SoapClient(NULL,
                             array('location' => 'https://example.com/ExampleWebServiceDL/services/ExampleHandler', 
                             'uri' => 'http://example.com/wsdl', 'trace' => 1));
                  $result = $client->$method($data);
                  

                  这是它创建的请求:

                    <?xml version="1.0" encoding="UTF-8"?>
                    <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://example.com/wsdl" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                      <SOAP-ENV:Body>
                        <ns1:Echo>
                          <param0 xsi:type="ns2:Map">
                            <item>
                              <key xsi:type="xsd:string">Acquirer</key>
                              <value xsi:type="ns2:Map">
                                <item>
                                  <key xsi:type="xsd:string">Id</key>
                                  <value xsi:type="xsd:string">mcp</value>
                                </item>
                                <item>
                                  <key xsi:type="xsd:string">UserId</key>
                                  <value xsi:type="xsd:string">tst001</value>
                                </item>
                                <item>
                                  <key xsi:type="xsd:string">Password</key>
                                  <value xsi:type="xsd:string">test</value>
                                </item>
                              </value>
                            </item>
                          </param0>
                        </ns1:Echo>
                      </SOAP-ENV:Body>
                    </SOAP-ENV:Envelope>
                  

                  这是我希望请求的样子:

                    <?xml version="1.0" encoding="UTF-8"?>
                    <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://example.com/wsdl" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                      <SOAP-ENV:Body>
                        <Echo>
                          <Acquirer>
                            <Id>MyId</Id>
                            <UserId>MyUserId</UserId>
                            <Password>MyPassword</Password>
                          </Acquirer>
                        </Echo>
                      </SOAP-ENV:Body>
                    </SOAP-ENV:Envelope>
                  

                  推荐答案

                  有几种方法可以解决这个问题.最简单的,几乎是您想要的:

                  There are a couple of ways to solve this. The least hackiest and almost what you want:

                  $client = new SoapClient(
                      null,
                      array(
                          'location' => 'https://example.com/ExampleWebServiceDL/services/ExampleHandler',
                          'uri' => 'http://example.com/wsdl',
                          'trace' => 1,
                          'use' => SOAP_LITERAL,
                      )
                  );
                  $params = new SoapVar("<Acquirer><Id>MyId</Id><UserId>MyUserId</UserId><Password>MyPassword</Password></Acquirer>", XSD_ANYXML);
                  $result = $client->Echo($params);
                  

                  这会为您提供以下 XML:

                  This gets you the following XML:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://example.com/wsdl">
                      <SOAP-ENV:Body>
                          <ns1:Echo>
                              <Acquirer>
                                  <Id>MyId</Id>
                                  <UserId>MyUserId</UserId>
                                  <Password>MyPassword</Password>
                              </Acquirer>
                          </ns1:Echo>
                      </SOAP-ENV:Body>
                  </SOAP-ENV:Envelope>
                  

                  这几乎正是您想要的,除了方法名称上的命名空间.我不知道这是否有问题.如果是这样,您可以进一步破解它.您可以手动将 <Echo> 标记放入 XML 字符串中,并通过添加 'style' => 让 SoapClient 不设置方法.SOAP_DOCUMENT, 到 options 数组如下:

                  That is almost exactly what you want, except for the namespace on the method name. I don't know if this is a problem. If so, you can hack it even further. You could put the <Echo> tag in the XML string by hand and have the SoapClient not set the method by adding 'style' => SOAP_DOCUMENT, to the options array like this:

                  $client = new SoapClient(
                      null,
                      array(
                          'location' => 'https://example.com/ExampleWebServiceDL/services/ExampleHandler',
                          'uri' => 'http://example.com/wsdl',
                          'trace' => 1,
                          'use' => SOAP_LITERAL,
                          'style' => SOAP_DOCUMENT,
                      )
                  );
                  $params = new SoapVar("<Echo><Acquirer><Id>MyId</Id><UserId>MyUserId</UserId><Password>MyPassword</Password></Acquirer></Echo>", XSD_ANYXML);
                  $result = $client->MethodNameIsIgnored($params);
                  

                  这会产生以下请求 XML:

                  This results in the following request XML:

                  <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
                      <SOAP-ENV:Body>
                          <Echo>
                              <Acquirer>
                                  <Id>MyId</Id>
                                  <UserId>MyUserId</UserId>
                                  <Password>MyPassword</Password>
                              </Acquirer>
                          </Echo>
                      </SOAP-ENV:Body>
                  </SOAP-ENV:Envelope>
                  

                  最后,如果你想玩转 SoapVar 和 SoapParam 对象,你可以在 PHP 手册的这个注释中找到一个很好的参考:http://www.php.net/manual/en/soapvar.soapvar.php#104065.如果你成功了,请告诉我,我失败得很惨.

                  Finally, if you want to play around with SoapVar and SoapParam objects, you can find a good reference in this comment in the PHP manual: http://www.php.net/manual/en/soapvar.soapvar.php#104065. If you get that to work, please let me know, I failed miserably.

                  这篇关于使用 PHP 和 XML 主体创建 SOAP 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP 使用哪个 SOAP 库? 下一篇:是否可以在 PHP 中咖喱方法调用?

                  相关文章

                  最新文章

                    <bdo id='5iKyk'></bdo><ul id='5iKyk'></ul>

                  <small id='5iKyk'></small><noframes id='5iKyk'>

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