繁体   English   中英

PHP在CURL中的SOAP请求

[英]SOAP request in PHP in CURL

自从我试图弄清楚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>

我也有以下数据:

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

基本上:

  1. PHP对SOAP的支持糟透了。
  2. 您需要使用WSDL来生成PHP类,以便可以构建Request对象。

您将获得如下内容:

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

有一些WSDL到PHP脚本。 (谷歌wsdl到PHP)

然后,您需要执行以下操作。

$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

无需实现“ GetVariants”方法,因此您不会感到困惑,也不必问自己应该从哪里得到它。WSLD中对它进行了描述,PHP的SOAP客户端知道这只是一个SOAP操作。

这应该是通过PHP创建SOAP请求的更高级的示例。 希望您了解这一基本流程。

暂无
暂无

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

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