【问题标题】:PHP SOAP Header does not match HTTP SOAP Action, how to set it?PHP SOAP Header 与 HTTP SOAP Action 不匹配,如何设置?
【发布时间】:2012-06-11 19:24:01
【问题描述】:

我什么都试过了!我正在使用这个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);

让我知道你的想法?

【问题讨论】:

    标签: php soap soap-client soapheader


    【解决方案1】:

    当尝试访问一个未知的网络服务时,你应该从soapUi 开始。 http://www.soapui.org/ 那会在 2 分钟内告诉你,那

    这是一个 SOAP 1.1 服务

    这是验证端口的最少内容:

    <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 会节省您的时间;)

    【讨论】:

    • SoapUI 摇滚,哈哈;我总是推荐它。
    【解决方案2】:

    更改 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.
    

    【讨论】:

      【解决方案3】:

      为了修复 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 内部服务器错误。

      【讨论】:

        猜你喜欢
        • 2011-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多