简体   繁体   English

PHP SoapClient 尝试使用 C# 生成的 WSDL 给出错误

[英]PHP SoapClient trying to consume a C# generated WSDL giving errors

So I'm trying to consume a WSDL generated by C# .NET application using PHP.所以我试图使用由 C# .NET 应用程序使用 PHP 生成的 WSDL。 I've ran into multiple issues and have worked my way up to this point where I cannot seem to find the next thing to do.我遇到了多个问题,并且一直工作到这一点,我似乎无法找到下一步要做的事情。

I'm using SOAP 1.2 to prevent the text/xml error from happening ( expected type application/soap+xml ), whereas SOAP 1.2 is accepted by the application as text/xml .我使用 SOAP 1.2 来防止发生text/xml错误( expected type application/soap+xml ),而应用程序接受 SOAP 1.2 作为text/xml

The error I receive now is:我现在收到的错误是:

[message:protected] => The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/IMembership/AcquireSecurityToken'.

I'm a little worried why it is not detected any action from my end ( '' ) but I have no clue what I'm doing wrong or what I should be approaching differently.我有点担心为什么它没有从我的一端( '' )检测到任何动作,但我不知道我做错了什么或我应该以不同的方式接近。

Underneath you'll find most of the relevant code involved in trying to get this to work for now.在下面,您会找到大多数相关代码,这些代码目前都试图让它发挥作用。

$params  = array("soap_version"=> SOAP_1_2,
                "trace"=>1,
                "exceptions"=>1,
                );


$client = new SoapClient("http://removed.for.now/Membership.svc?wsdl", $params);
$actionHeader = new SoapHeader('http://www.w3.org/2005/08/addressing','AcquireSecurityToken', 'http://tempuri.org/IMembership/AcquireSecurityToken',true);
$client->__setSoapHeaders($actionHeader);

$args = array("username"=>"user", "password"=>"goodpw");

try { 
    $result = $client->AcquireSecurityToken($args);
} catch(Exception $e) {
    echo "<h1>Last request</h1>";
    // print_r the error report. Omitted for clarity.
}

Any tips or suggestions?任何提示或建议? Things I'm not doing right or should be trying differently?我做的不对或应该尝试不同的事情?

I figured it out with the help of some lovely people on IRC.我在 IRC 上一些可爱的人的帮助下弄明白了。

The ActionHeader that I tried to add using $actionHeader was close, but not correct.我尝试使用$actionHeader添加的 ActionHeader 很接近,但不正确。

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

Did the trick.做到了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM