我必须了解如何使用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>
我尝试了三种都不起作用的结构
“新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";
错误消息卡在其中:
实际发送执行:
$soap_response = $soapClient->ServerMethod($soap_request);
此刻我真的停滞了,甚至不知道要搜索错误/错误,因为我没有任何要调试的“好”详细错误。
这是我第一次必须使用SOAP(将数据发送到服务),也许我完全错了吗?非常感谢您的帮助。
核心问题:
php内部的结构在所有名称空间中的外观如何, 属性,嵌套元素?
答案 0 :(得分:0)
问题是内置的php函数SoapHeader没有提供与wsse兼容的Soap-Header。再往下看,您可以通过扩展php SoapHeader类来查看实现。
我将stdClass对象用作有效负载。通过将所有属性传递到最深的对象层来获取实际数据字段。
我希望我可以为我的问题的答案节省一些研究。
有一个不错的人。
安全性肥皂标头:
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>