我目前正在尝试在c#中调用PHP Web服务。我已经尝试了很多在互联网上找到的解决方案,但都没有成功,也没有与我的问题相同的。我对PHP不太熟悉。
我可以成功地从我的c#中调用authenticate_get。
string auth_id = client.authenticate_get("www.testexample.com", "e5d30c56d600a7456846164");
获取返回的认证ID,但不知道如何在C#中传递数组。这里给出了PHP示例。
<?php
$client = new SoapClient("https://example.com/TESTApi_v1_1.wsdl.php");
$auth_id = $client->authenticate_get('username', 'password');
$client = new SoapClient("https://example.com/TESTApi_v1_1.wsdl.php", array("login" => $auth_id ));
?>
当我尝试调用其他方法时,只会返回一个错误信息:"需要HTTP基本授权头"。
我也尝试了以下方法:
Uri uri = new Uri(url);
ICredentials credentials = netCredential.GetCredential(uri, "Basic login:" + auth_id);
client.Credentials = credentials;
client.PreAuthenticate = true;
我也一直在尝试:
public class MyHeader : SoapHeader
{
public string login;
}
[WebService(Namespace = "https://example.com/TESTApi_v1_1.wsdl.php")]
public class exampleTestService : ExampleService
{
public MyHeader myOutHeader;
[WebMethod]
[SoapHeader("login", Direction = SoapHeaderDirection.InOut)]
public MyHeader MyOutHeaderMethod()
{
var client = new ExampleService();
string auth_id = client.authenticate_get("www.testexample.com", "e5d30c56d600a7e6f3cef05d8c0a1991");
// Return the client's authenticated name.
MyHeader outHeader = new MyHeader();
outHeader.login = auth_id;
return outHeader;
}
}
我相信我缺少了一些简单的东西。
提前感谢您的帮助。