[英]soap call to .net from php paramaters not passing
我試圖讓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::: )
因此,憑據可以正確傳遞,但值永遠無法實現。 有幫助嗎?
.NET根本無法正確執行SOAP。 我再也無法訪問代碼了,但是我認為您需要做一些荒謬的事情,例如將屬性包裝在名為“ parameters”的鍵下的另一個關聯數組中。
我認為您必須為參數使用關聯數組:
array("id" => "test1234")
所以你的電話:
print_r($client->add(array("id" => "test1234"));
文檔PHP.NET: http://php.net/manual/fr/soapclient.soapcall.php#110390
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.