2

我什么都试过了!我正在使用这个WSDL,只是想进行身份验证。我不断收到此错误:

消息上指定的 SOAP 操作“”与 HTTP SOAP 操作“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);

让我知道你的想法?

4

3 回答 3

3

当试图访问一个未知的网络服务时,你应该从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>

他们的messagerouter必须单独基于soap-action,所以使用Action是没有意义和不必要的

所以是的,使用soapUi 会节省你的时间;)

于 2012-06-27T04:07:16.217 回答
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.
于 2012-06-23T08:08:06.473 回答
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 内部服务器错误。

于 2012-06-23T06:53:19.400 回答