我已经尝试了一切!我正在使用此WSDL而我只是想尝试进行身份验证。我一直收到这个错误:
在消息上指定的SOAP操作''与HTTP不匹配 SOAP Action,'http://tempuri.org/IPSShipCarrier/Authenticate'
这是我的代码:
$options = array(
"soap_version" => SOAP_1_2,
"trace"=>1,
'UserName'=>'blahremoved',
'Password'=>'blahremoved',
'AuthToken'=>'blahremoved',
'SOAPAction'=>'http://tempuri.org/IPSShipCarrier/Authenticate',
'Action'=>'http://tempuri.org/IPSShipCarrier/Authenticate',
'uri'=>'http://tempuri.org/IPSShipCarrier/Authenticate',
'exceptions'=>true );
$client = new SoapClient( "http://test.psdataservices.com/PSShipCarrierAPI/PSShipCarrier.svc?WSDL", $options );
$auth = array(
'UserName'=>'blahremoved',
'Password'=>'blahremoved',
'AuthToken'=>'blahremoved',
'SOAPAction'=>'http://tempuri.org/IPSShipCarrier/Authenticate',
'Action'=>"Authenticate"
);
$header = new SoapHeader('http://tempuri.org/IPSShipCarrier/Authenticate','Authenticate',$auth,false);
$client->__setSoapHeaders($header);
$params = new StdClass;
$params->Action = "http://tempuri.org/IPSShipCarrier/Authenticate";
$params->SOAPAction = "http://tempuri.org/IPSShipCarrier/Authenticate";
$params->UserName = "blahremoved";
$params->Password = "blahremoved";
$params->AuthToken = "blahremoved";
$client->Authenticate($params);
让我知道你的想法?
答案 0 :(得分:3)
当尝试访问-yet-未知的Web服务时,您应该从soapUi开始。 http://www.soapui.org/那会在2分钟内告诉你,
这是一个SOAP 1.1服务
这是Authenticate端口的最小内容:
<tem:Authenticate>
<!--Optional:-->
<!--type: string-->
<tem:ClientName>aat</tem:ClientName>
<!--Optional:-->
<!--type: string-->
<tem:UserName>soa</tem:UserName>
<!--Optional:-->
<!--type: string-->
<tem:Password>quaaao</tem:Password>
<!--Optional:-->
<!--type: string-->
<tem:AuthToken>verraauras</tem:AuthToken>
<!--Optional:-->
<!--type: scShipCarrier - enumeration: [scUnknown,scStampsCom,scUPS,scEndicia,scFedEx]-->
<tem:ShipCarr>scUnknown</tem:ShipCarr>
</tem:Authenticate>
他们的消息路由器必须仅基于soap-action,因此使用Action是毫无意义且不必要的
所以是的,使用soapUi可以节省你的一天;)
答案 1 :(得分:0)
要修复Content-Type标头问题,我将soap_version切换为SOAP_1_1
"soap_version" => SOAP_1_1,
然后我得到了一个更有趣的错误消息,Christian Burger曾经让我们进一步包含ShipCarr参数。
在此基础上,我查看了XSD,这里有一个更新的$ params值:
$params->ShipCarr = 'scUnknown';
这返回:
POST /PSShipCarrierAPI/PSShipCarrier.svc HTTP/1.1
Host: test.psdataservices.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.3.8
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/IPSShipCarrier/Authenticate"
Content-Length: 856
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:ns2="http://tempuri.org/IPSShipCarrier/Authenticate"><SOAP-ENV:Header><ns2:Authenticate><item><key>UserName</key><value>blahremoved</value></item><item><key>Password</key><value>blahremoved</value></item><item><key>AuthToken</key><value>blahremoved</value></item><item><key>SOAPAction</key><value>http://tempuri.org/IPSShipCarrier/Authenticate</value></item><item><key>Action</key><value>Authenticate</value></item></ns2:Authenticate></SOAP-ENV:Header><SOAP-ENV:Body><ns1:Authenticate><ns1:UserName>blahremoved</ns1:UserName><ns1:Password>blahremoved</ns1:Password><ns1:AuthToken>blahremoved</ns1:AuthToken><ns1:ShipCarr>scUnknown</ns1:ShipCarr></ns1:Authenticate></SOAP-ENV:Body></SOAP-ENV:Envelope>
HTTP/1.1 200 OK
Content-Length: 325
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Mon, 25 Jun 2012 20:34:42 GMT
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><AuthenticateResponse xmlns="http://tempuri.org/"><AuthenticateResult i:nil="true" xmlns:a="http://schemas.datacontract.org/2004/07/ShipCarriers.Contract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/></AuthenticateResponse></s:Body></s:Envelope>
但是,后续请求会给我一个500内部服务器错误。
答案 2 :(得分:0)
更改SOAP版本肯定会让您更进一步。但是,从查看堆栈跟踪看来,Authenticate方法似乎需要您未设置的参数。这是您需要的最小代码,不知道shipCarr对象应该是什么样的:
$options = array(
"soap_version" => SOAP_1_1,
"trace"=>1,
'exceptions'=>true,
);
$client = new SoapClient( "http://test.psdataservices.com/PSShipCarrierAPI/PSShipCarrier.svc?WSDL", $options );
$params = new StdClass();
$params->UserName = "blahremoved";
$params->Password = "blahremoved";
$params->AuthToken = "blahremoved";
$params->ShipCarr = array();
$params->ClientName = "blahremoved";
$response = $client->Authenticate($params);
var_dump($response);
这是回复:
[a:DeserializationFailed] The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:ShipCarr. The InnerException message was 'Invalid enum value 'Array' cannot be deserialized into type 'ShipCarriers.Contract.scShipCarrier'. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.'. Please see InnerException for more details.