简体   繁体   English

PHP在CURL中的SOAP请求

[英]SOAP request in PHP in CURL

It's have been already several days since I'm trying to figure out SOAP but no success :( Any chance to know how can I create PHP(curl) SOAP request to look like this? 自从我试图弄清楚SOAP以来已经有好几天了,但是没有成功:(有机会知道如何创建PHP(curl)SOAP请求看起来像这样吗?

POST /WebServices/domain.asmx HTTP/1.1
Host: webservices.domain.ru
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.domain.ru/GetVariants"


<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <AuthentificationHeader xmlns="http://www.domain.ru/">
      <Login>string</Login>
      <Password>string</Password>
      <PartnerId>string</PartnerId>
    </AuthentificationHeader>
  </soap:Header>
  <soap:Body>
    <GetVariants xmlns="http://www.domain.ru/">
      <RequestParameters>xml</RequestParameters>
    </GetVariants>
  </soap:Body>
</soap:Envelope>

Also I have following data: 我也有以下数据:

WSDL: 
http://webservices.domain.ru/WebServices/domainXml.asmx?WSDL
Soap action: 
http://webservices.domain.ru/WebServices/domainXml.asmx?op=GetVariants

Basically: 基本上:

  1. PHP's support for SOAP just sucks. PHP对SOAP的支持糟透了。
  2. You need to use your WSDL to generate your PHP classes, so you can build a Request object. 您需要使用WSDL来生成PHP类,以便可以构建Request对象。

You will get something like this: 您将获得如下内容:

class SomeClass
{
    var $name; //NCName
}
class SomeOtherClass
{
    var $value; //anonymous2
}
.
.
.

There are some WSDL to PHP scripts out there. 有一些WSDL到PHP脚本。 (Google wsdl to php) (谷歌wsdl到PHP)

Then you do something like this. 然后,您需要执行以下操作。

$soapClient = new SoapClient($this->_wsdlUrl, array(
                'trace' => true,
                'exceptions' => true,
                'uri' => $this->_endPoint,
                'location' => $this->_endPoint,
                'local_cert' => $this->certificatePath,
                'allow_self_signed' => true,
                'soap_version' => SOAP_1_2,
            ));
// Build the SOAP client object, with your properties.

//After that, you have to call:
$yourContainerObject = new YourContainerObject(); // The top SOAP XML node 
$yourContainerObject->SomeChildNode = new SomeChildNode();
$yourContainerObject->SomeChildNode->Name = 'John';
.
.
.

$soapResponse = $soapClient->GetVariants($yourContainerObject);
print_r(soapResponse); // to see what you get

The "GetVariants" method doesn't need to be implemented, so you don't get confused and ask yourself where do I get that from.It is described in WSLD and PHP's SOAP client knows that it is just a SOAP action. 无需实现“ GetVariants”方法,因此您不会感到困惑,也不必问自己应该从哪里得到它。WSLD中对它进行了描述,PHP的SOAP客户端知道这只是一个SOAP操作。

This should be an more advanced example of creating SOAP requests via PHP. 这应该是通过PHP创建SOAP请求的更高级的示例。 I hope you get the basic flow of this. 希望您了解这一基本流程。

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

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