PHP Array/Object SOAP 的结构 (WSDL/wsse)
PHP Array/Object Structure for SOAP (WSDL/wsse)
我必须了解如何使用 PHP 生成此示例 WSDL 的结构。 (SoapClient、SoapHeaders)
假设实际输出应该是这样的:
<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>
我尝试了三种不同的结构,其中 none 有效
- 新\stdClass();
- 新建\ArrayObject();
- 数组()
"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);
“$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;
}
我尝试调试结构的东西:
echo "FNs:\n" . $soapClient->__getFunctions() . "\n";
echo "REQUEST:\n" . $soapClient->__getLastRequest() . "\n";
echo "REQUEST (htmlent):\n" . htmlentities($soapClient->__getLastRequest()) . "\n";
我遇到的错误消息:
- 输入格式不正确或不包含预期数据
- 调用 PropertySet.GetChild() 失败。 (属性 集没有任何子集。(SBL-EXL-00144))
实际发送执行:
$soap_response = $soapClient->ServerMethod($soap_request);
好吧,我现在真的卡住了,甚至不知道是否要搜索 errors/mistakes,因为我没有任何要调试的 "good" 详细错误。
这是我第一次必须使用 SOAP(将数据发送到服务),也许我完全错了?非常感谢帮助。
核心问题:
how does the structure inside php look like with all the namespaces,
attributes, nested Elements?
问题是内置 php 函数 SoapHeader 不提供符合 wsse 的 Soap-Header。再往下,您可以通过扩展 php SoapHeader class.
来查看实现
我使用了一个 stdClass object 作为负载。和实际数据字段,方法是将所有属性传递到最深的 object 层。
我希望我可以通过我的问题的答案为某人节省一些研究。
祝你好运。
安全皂 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 负载:
$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;
}
这导致以下 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>
我必须了解如何使用 PHP 生成此示例 WSDL 的结构。 (SoapClient、SoapHeaders)
假设实际输出应该是这样的:
<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>
我尝试了三种不同的结构,其中 none 有效
- 新\stdClass();
- 新建\ArrayObject();
- 数组()
"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);
“$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;
}
我尝试调试结构的东西:
echo "FNs:\n" . $soapClient->__getFunctions() . "\n";
echo "REQUEST:\n" . $soapClient->__getLastRequest() . "\n";
echo "REQUEST (htmlent):\n" . htmlentities($soapClient->__getLastRequest()) . "\n";
我遇到的错误消息:
- 输入格式不正确或不包含预期数据
- 调用 PropertySet.GetChild() 失败。 (属性 集没有任何子集。(SBL-EXL-00144))
实际发送执行:
$soap_response = $soapClient->ServerMethod($soap_request);
好吧,我现在真的卡住了,甚至不知道是否要搜索 errors/mistakes,因为我没有任何要调试的 "good" 详细错误。
这是我第一次必须使用 SOAP(将数据发送到服务),也许我完全错了?非常感谢帮助。
核心问题:
how does the structure inside php look like with all the namespaces, attributes, nested Elements?
问题是内置 php 函数 SoapHeader 不提供符合 wsse 的 Soap-Header。再往下,您可以通过扩展 php SoapHeader class.
来查看实现我使用了一个 stdClass object 作为负载。和实际数据字段,方法是将所有属性传递到最深的 object 层。
我希望我可以通过我的问题的答案为某人节省一些研究。
祝你好运。
安全皂 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 负载:
$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;
}
这导致以下 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>