soap从php参数调用.net而不是传递

时间:2012-11-14 16:05:48

标签: php .net web-services soap

我试图让php只是简单地将一个参数传递给.net Web服务,但是它从不会将参数添加到调用中,但它会调用该函数。

这是php:

$client = new SoapClient("example.com/page.asmx?WSDL");
$header = new SoapHeader('example.com/', 'UserCredentials', 
    array(
        'userName' => "cory", 
        'password' => "test", 
    )
);
$client->__setSoapHeaders(array($header));

print_r($client->add("test1234"));

这是.net

[WebMethod]
[SoapHeader( "consumer", Required = true )]
public string add( string id )
{
    if( id == null || id != "test1234" ) {
       return "ID Invalid: " + consumer.ToString() + ":::" + id;
    }
    return "good";
}

public class UserCredentials : System.Web.Services.Protocols.SoapHeader
{
    public string userName;
    public string password;

    public override string ToString()
    {
        return userName + ":" + password;
    }
}

每当我运行它,它将打印

stdClass Object ( [addResult] => ID Invalid: cory:test::: )

因此,凭据正确传递但值永远不会成功。任何帮助?

2 个答案:

答案 0 :(得分:0)

.NET根本无法正确执行SOAP。我再也无法访问代码,但我相信你需要做一些荒谬的事情,比如将你的属性包装在名为'parameters'的键下的另一个关联数组中。

Here's my answered question that got my application working.

答案 1 :(得分:0)

我认为您必须为参数使用关联数组:

array("id" => "test1234") 

所以你的肥皂叫:

print_r($client->add(array("id" => "test1234"));

文档PHP.NET:http://php.net/manual/fr/soapclient.soapcall.php#110390