我试图让 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::: )
因此凭据正确传递,但值永远不会成功。有什么帮助吗?