質問

I am trying to create this :

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<AccessKey xmlns="http://eatright/membership" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Value>67a4ef47-9ddf-471f-b6d0-0000c28d57d1</Value>
</AccessKey>
</s:Header>
<s:Body>
<WebUserLogin xmlns="http://eatright/membership">
<loginOrEmail>1083790</loginOrEmail>
<password>thomas</password>
</WebUserLogin>
</s:Body>
</s:Envelope>

I created this PHP code

    class ChannelAdvisorAuth 
{ 
    public $AccessKey ; 

    public function __construct($key) 
    { 
        $this->AccessKey = $key; 
    } 
} 
$AccessKey     = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 
$url         = "http://ws.eatright.org/service/service.svc?wsdl"; 
$client     = new SoapClient($url, array("trace" => 1, "exception" => 0)); 
$auth         = new ChannelAdvisorAuth($AccessKey); 
$header     = new SoapHeader("AccessKey", "Value", $AccessKey, false);
$client->__setSoapHeaders($header); 
$result = $client->ValidateAccessKey();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";

The output of the above PHP code is :

    <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://eatright/membership" xmlns:ns2="AccessKey">
<SOAP-ENV:Header>
<ns2:Value>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</ns2:Value>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:ValidateAccessKey/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

How to change the PHP code to output the XML as requested by web service provider?

How to replace the "SOAP-ENV" to "S"?

Is there is a way to remove the NS1 and NS2? and also adjust the whole format of the XML to meet the requirements? thanks

役に立ちましたか?

解決

You don't need to worry about SOAP-ENV, ns1 or ns2 - they are just prefixes referring to the namespaces. As long as the full namespaces are correct, it's going to be alright.

I think the SOAP header should be made like this:

$access_key = new stdClass();
$access_key->Value = 'XXX';

$hdr = new SoapHeader('http://eatright/membership', 'AccessKey', $access_key);
$client->__setSoapHeaders($hdr);

I don't see a purpose of xmlns:i in the first example - there are no elements having XSI attributes.

I'm not sure what to do with the body. In your first example, there is a call to the WebUserLogin operation, while in your PHP code you are trying to call ValidateAccessKey.

Have you tried reading the WSDL file which is pointed by $url

他のヒント

Ok I found the problem and I will add it here in case someone looking for same issue.

$access_key = new stdClass();
$access_key->Value = 'xxxxxxxxxxxxxxxxxxx';
// Create the SoapClient instance 
$url         = "http://ws.eatright.org/service/service.svc?wsdl"; 
$client     = new SoapClient($url, array("trace" => 1, "exception" => 0)); 
$hdr = new SoapHeader('http://eatright/membership', 'AccessKey', $access_key);
$client->__setSoapHeaders($hdr);
$soapParameters = array('loginOrEmail ' => $username, 'password' => $password);
$login = new stdClass();
$login->loginOrEmail='LoginID';
$login->password='Password';
$result = $client->WebUserLogin($login);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top