Submitting data to Soap Server with PHP
I am unable to pass the header to the WSDL for credencials:
this is the code:
$soapClient = new SoapClient("https://www.em-sender.com/ws/InwiseWebServices.asmx?WSDL");
$header = array('user'=>'user1','pass'=>'pass1');
$soapClient->__setSoapHeaders(new SoapHeader("https://www.em-sender.com/ws/InwiseWebServices.asmx?WSDL",'SecHeader',$header));
$res = $soapClient->__call("Recipients_checkUnsubscribed", array('email'=> 'test@test.com'));
var_dump($res);
I am getting the following error:
Fatal error: Uncaught SoapFault exception: [soap:Client] Please provide security header in...
this is the WSDL description: https://www.em-sender.com/ws/InwiseWebServices.asmx?op=Recipients_checkUnsubscribed
or see here:
POST /ws/InwiseWebServices.asmx HTTP/1.1
Host: www.em-sender.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Header>
<SecHeader xmlns="http://www.inwise.com/schemas">
<username>string</username>
<pass>string</pass>
</SecHeader>
<AuthIdentifier xmlns="http://www.inwise.com/schemas">
<identifier>string</identifier>
</AuthIdentifier>
</soap12:Header>
<soap12:Body>
<Recipients_checkUnsubscribed xmlns="http://www.inwise.com/schemas">
<email>string</email>
</Recipients_checkUnsubscribed>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<Recipients_checkUnsubscribedResponse xmlns="http://www.inwise.com/schemas">
<Recipients_checkUnsubscribedResult>boolean</Recipients_checkUnsubscribedResult>
</Recipients_checkUnsubscribedResponse>
</soap12:Body>
</soap12:Envelope>
Edit
This is the sent string:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.inwise.com/schemas" xmlns:ns2="https://www.em-sender.com/ws/InwiseWebServices.asmx?WSDL">
<SOAP-ENV:Header>
<ns2:SecHeader>
<item>
<key>user</key&开发者_JS百科gt;
<value>user1</value>
</item>
<item>
<key>pass</key>
<value>pass1</value>
</item>
</ns2:SecHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:Recipients_checkUnsubscribed/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I have reviewed your SOAP request, and if you exactly compare you can see two problems:
- The key/value pairs weren't okay (should be username and pass)
- The namespace of the soapheader was incorrect.
If I try the following then I get a error message telling my credentials are invalid which makes sense because I just filled in something. I won't get the security header fault anymore.
$soapClient = new SoapClient("https://www.em-sender.com/ws/InwiseWebServices.asmx?WSDL", array('trace' => true));
$header = new SoapVar(array('username' => 'user', 'pass' => 'password'), SOAP_ENC_OBJECT);
$soapClient->__setSoapHeaders(new SoapHeader("http://www.inwise.com/schemas",'SecHeader',$header));
try {
$res = $soapClient->Recipients_checkUnsubscribed('test@test.com');
var_dump($res);
} catch(SoapFault $fault) {
var_dump($soapClient->__getLastRequest());
var_dump($fault->getMessage());
}
精彩评论