【问题标题】:SOAP error using PHP SoapClient使用 PHP SoapClient 的 SOAP 错误
【发布时间】:2016-06-28 06:39:15
【问题描述】:

我正在尝试使用 PHP 的 SoapClient 连接到 Soap Web 服务,但出现以下错误

在消息 '' 上指定的 SOAP 操作与 HTTP 不匹配 SOAP 操作,'http://tempuri.org/IInDirect/AddProduct'。

下面是我连接到服务器的 PHP 代码。

$requestParams = array(
    'Password' => 'XXXXXX',
    'Username' => 'XXXXXXX',
    'AddressLine1' => '52 TEST DRIVE',
    'City' => 'JOHANNESBURG',
    'DateOfBirth' => '1960-02-10T00:00:00',
    'Forename1' => 'Eva',
    'Gender' => 'Unknown',
    'Province' => 'GAUTENG',
    'SouthAfricanID' => '45454545454',
    'ProductCode' => '12345'
);

try {

    $options = array(
    'soap_version' => SOAP_1_2,
    'cache_wsdl'=>WSDL_CACHE_NONE,
    'connection_timeout' => 15,
    'trace' => true,
    'encoding' => 'UTF-8',
    'exceptions' => true,
    );

$client = new \SoapClient('https://soap.url.com/test.svc?wsdl', $options);

$actionHeader = new \SoapHeader('http://www.w3.org/2005/08/addressing',
            'Action',
            'http://tempuri.org/IInDirect/AddProduct');
        $client->__setSoapHeaders($actionHeader);

} catch (Exception $e) {
    echo "<h2>Exception Error!</h2>";
    echo $e->getMessage();
}
$response = $client->AddProduct($requestParams);

print_r($response);

下面是xml

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tusa="http://schemas.datacontract.org/2004/07/Tusa.Services.ConsumerConnect" xmlns:tem="http://tempuri.org/">
<soap:Header>
    <AuthenticationCredentials>
    <tusa:Password>Password</tusa:Password>
    <tusa:Username>Username</tusa:Username>
    </AuthenticationCredentials>
</soap:Header>
<soap:Body>
    <tem:AddProduct>
    <tem:CustomerDetail>
    <tusa:AddressLine1>AddressLine1</tusa:AddressLine1>           
    <tusa:City>City</tusa:City>
    <tusa:DateOfBirth>DateOfBirth</tusa:DateOfBirth>            
    <tusa:Forename1>Forename1</tusa:Forename1>        
    <tusa:Gender>Gender</tusa:Gender>
    <tusa:MaritalStatus>MaritalStatus</tusa:MaritalStatus>           
    <tusa:Province>Province</tusa:Province>
    <tusa:SouthAfricanID>SouthAfricanID</tusa:SouthAfricanID>           
    <tusa:Suburb>Suburb</tusa:Suburb>
    <tusa:Surname>Surname</tusa:Surname>     
    </tem:CustomerDetail>
    <tem:ProductCode>ProductCode</tem:ProductCode>
    </tem:AddProduct>
</soap:Body>
</soap:Envelope>

我该如何让它工作?

【问题讨论】:

    标签: php web-services soap soap-client


    【解决方案1】:

    此错误消息可能是由于缺少 Action SOAP 标头造成的。

    $actionHeader = new SoapHeader('http://www.w3.org/2005/08/addressing',
                                   'Action',
                                   'http://tempuri.org/IInDirect/AddProduct');
    $client->__setSoapHeaders($actionHeader);
    

    【讨论】:

    • 你能解释一下你从哪里得到这 3 个参数吗?
    • 请注意,如果缺少动作标头,soap 可能会返回错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-07
    • 2022-11-11
    相关资源
    最近更新 更多