简体   繁体   English

SOAP的PHP数组/对象结构(WSDL / wsse)

[英]PHP Array/Object Structure for SOAP (WSDL/wsse)

i have to understand how a structure for this sample WSDL could be generated with PHP. 我必须了解如何使用PHP生成此示例WSDL的结构。 (SoapClient, SoapHeaders) (SoapClient,SoapHeaders)

lets say the actual output should look like this: 可以说实际输出应如下所示:

<soapenv:Envelope xmlns="http://schemas.xmlsoap.org/1">
    <soapenv:Header>
        <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/3">
         <wsse:UsernameToken xmlns:wsu="http://schemas.xmlsoap.org/4">
          <wsse:Username>name</wsse:Username>
          <wsse:Password Type="wsse:PasswordText">good_password</wsse:Password>
         <wsse:UsernameToken>
        </wsse:Security>    
    </soapenv:Header>

    <soapenv:Body>
      <asi:ProcessMsg>
        <req:Payload>
          <req:Request>
            <req:Sub>DATA_1</req:Sub>
            <req:EID>DATA_2</req:EID>
            <req:IID>DATA_3</req:IID>
            <req:Customer FirstName="xxx" LastName="xxx"></req:Customer>
            <req:Lead LeadMaster="xxx" IntendedRepPer="xxx"></req:Lead>
          </req:Request>
        </req:Payload>
      </asi:ProcessMsg>
    </soapenv:Body>

   </soapenv:Envelope>

i've tried three different structures which none of them worked 我尝试了三种都不起作用的结构

  • new \\stdClass(); 新\\ stdClass();
  • new \\ArrayObject(); 新\\ ArrayObject();
  • array() array()

Structure for "new SoapHeader();" “ new SoapHeader();”的结构

 $Security = new \ArrayObject();
 $Security['UsernameToken'] = new \ArrayObject();
 $Security['UsernameToken']['Username'] = "name";
 $Security['UsernameToken']['Password'] = "good_password";

 // OR

 $Security = new \stdClass();
 $Security->UsernameToken = new \stdClass();
 $Security->UsernameToken->Username = "name";
 $Security->UsernameToken->Password = "good_password";


$header = new SoapHeader('http://schemas.xmlsoap.org/ws/2002/07/secext','Security',$Security,false);
$soapClient->__setSoapHeaders($header);

Structure for "$soap_client->ServerMethod("Payload", $soap_request);": “ $ soap_client-> ServerMethod(“ Payload”,$ soap_request);“的结构:

$soap_request = new \ArrayObject();
$soap_request['Payload'] = new \ArrayObject();
$soap_request['Payload']['Request'] = new \ArrayObject();
$soap_request['Payload']['Request']['Sub'] = "xxx";
$soap_request['Payload']['Request']['EID'] = "xxx";
$soap_request['Payload']['Request']['IID'] = "xxx";
$soap_request['Payload']['Request']['Customer'] = new \ArrayObject();
$soap_request['Payload']['Request']['Customer']['_'] = '';

$soap_request['Payload']['Request']['Lead'] = new \ArrayObject();
$soap_request['Payload']['Request']['Lead']['_'] = '';


foreach ($data['x'] as $key => $value)
{
    $soap_request['Payload']['Request']['Customer'][$key] = $value;
}
foreach ($data['xx'] as $key => $value)
{
    $soap_request['Payload']['Request']['Lead'][$key] = $value;
}

// OR

$soap_request = new \stdClass();
$soap_request->Request = new \stdClass();
$soap_request->Request->Sub = "xxx";
$soap_request->Request->EID = "xxx";
$soap_request->Request->IID = "xxx";
$soap_request->Request->Customer = new \ArrayObject();
$soap_request->Request->Customer['_'] = '';
$soap_request->Request->Lead = new \ArrayObject();
$soap_request->Request->Lead['_'] = '';
foreach ($data['customer'] as $key => $value)
{
    $soap_request->Request->Customer[$key] = $value;
}
foreach ($data['lead'] as $key => $value)
{
    $soap_request->Request->Lead[$key] = $value;
}

things i tried to debug structures: 我尝试调试结构的事情:

echo "FNs:\n" . $soapClient->__getFunctions() . "\n";
echo "REQUEST:\n" . $soapClient->__getLastRequest() . "\n";
echo "REQUEST (htmlent):\n" . htmlentities($soapClient->__getLastRequest()) . "\n";

Error messages im stuck with: 错误消息卡住了:

  • Input is not well formed or does not contain the expected data 输入的格式不正确或不包含预期的数据
  • Call to PropertySet.GetChild() failed. 调用PropertySet.GetChild()失败。 (The property set does not have any children.(SBL-EXL-00144)) (该属性集没有任何子级。(SBL-EXL-00144))

the actual send execution: 实际发送执行:

$soap_response = $soapClient->ServerMethod($soap_request);

well im really stuck at the moment and do not know were to even search for errors/mistakes because i do not have any "good" verbose errors to debug. 好吧即时消息真的停留在此刻,甚至不知道要搜索错误/错误,因为我没有任何“好”冗长的错误可以调试。

its the first time i have to use SOAP (sending data to a service) and maybe i got it completely wrong? 这是我第一次必须使用SOAP(将数据发送到服务),也许我完全错了吗? help is very much appreciated. 非常感谢您的帮助。

the core question: 核心问题:

how does the structure inside php look like with all the namespaces, attributes, nested Elements? php内部的结构与所有名称空间,属性和嵌套元素如何相像?

the problem was that the built in php function SoapHeader does not provide an wsse compliant Soap-Header. 问题是内置的php函数SoapHeader没有提供与wsse兼容的Soap-Header。 further down you can see the implementation by extending the php SoapHeader class. 再往下看,您可以通过扩展php SoapHeader类来查看实现。

i used a stdClass object for the payload. 我为负载使用了stdClass对象。 and the actual data fields by passing all attributes to the deepest object layer. 通过将所有属性传递到最深的对象层来获取实际数据字段。

i hope i can save someone a little research with the answer to my question. 我希望我可以为我的问题的答案节省一些研究。

have a nice one. 有一个不错的。

Security Soap Header: 安全肥皂标头:

namespace AppName\TheBundle\Services;

use SoapHeader;
use SoapVar;

class AuthSoapHeaderHelper extends SoapHeader
{
    private $wss_ns = 'http://schemas.xmlsoap.org/.../secext';
    private $username = "username"; 
    private $password = "good_password"; 

    function __construct()
    {

        $auth = new \stdClass();
        $auth->Username = new SoapVar($this->username, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
        $auth->Password = new SoapVar($this->password, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);

        $username_token = new \stdClass();
        $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);

        $security_sv = new SoapVar(
            new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
            SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
        parent::__construct($this->wss_ns, 'Security', $security_sv, true);
    }
}

SOAP Payload: SOAP有效负载:

$soap_request = new \stdClass();
$soap_request->Payload = new \stdClass();
$soap_request->Payload->Request = new \stdClass();
$soap_request->Payload->Request->Sub = "DATA_1";
$soap_request->Payload->Request->EID = "DATA_2";
$soap_request->Payload->Request->IID = "DATA_3";
$soap_request->Payload->Request->Customer = new \stdClass();
$soap_request->Payload->Request->Lead = new \stdClass();

foreach ($data['x'] as $key => $value)
{
    $soap_request->Payload->Request->Customer->{$key} = $value;
}
foreach ($data['xx'] as $key => $value)
{
    $soap_request->Payload->Request->Lead->{$key} = $value;
}

which resulted in following wsdl/xml structure: 这导致以下wsdl / xml结构:

<soapenv:Envelope xmlns="http://schemas.xmlsoap.org/1">
    <soapenv:Header>
        <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/3">
         <wsse:UsernameToken xmlns:wsu="http://schemas.xmlsoap.org/4">
          <wsse:Username>username</wsse:Username>
          <wsse:Password Type="wsse:PasswordText">good_password</wsse:Password>
         <wsse:UsernameToken>
        </wsse:Security>    
    </soapenv:Header>

    <soapenv:Body>
      <asi:ProcessMsg>
        <req:Payload>
          <req:Request>
            <req:Sub>DATA_1</req:Sub>
            <req:EID>DATA_2</req:EID>
            <req:IID>DATA_3</req:IID>
            <req:Customer FirstName="xxx" LastName="xxx"></req:Customer>
            <req:Lead LeadMaster="xxx" IntendedRepPer="xxx"></req:Lead>
          </req:Request>
        </req:Payload>
      </asi:ProcessMsg>
    </soapenv:Body>

   </soapenv:Envelope>

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

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