Csharp/C#教程:从c#调用PHP Web服务分享


从c#调用PHP Web服务

我目前正在尝试用c#调用PHP Web服务。 我一直在尝试在互联网上找到的几十种解决方案,但没有运气,没有一个与我有同样的问题。 我不熟悉PHP。

我可以从c#中成功调用authenticate_get

string auth_id = client.authenticate_get("www.testexample.com", "e5d30c56d600a7456846164"); 

并获取返回的身份validationID,但后来不知道如何在c#中传递数组。 这是给出的PHP示例。

 authenticate_get('username', 'password'); $client = new SoapClient("https://example.com/TESTApi_v1_1.wsdl.php", array("login" => $auth_id )); ?> 

当我尝试调用任何其他方法时,我只是得到一个错误,返回“需要HTTP Basic Authorization头”。

我也尝试过:

 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; } } 

我确信我错过了一些简单的事情。

预先感谢您的任何帮助。

我有它的工作。 万一其他人可以找到我的答案有用:

上述就是C#学习教程:从c#调用PHP Web服务分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

  public partial class TheWebServiceSubClass : ExampleService { protected override WebRequest GetWebRequest(Uri uri) { HttpWebRequest webRequest = (HttpWebRequest)base.GetWebRequest(uri); ExampleService client = new ExampleService(); string auth_id = client.authenticate_get("www.testexample.com", "e5d30c56d600a7456846164"); string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("www.testexample.com:e5d30c56d600a7456846164")); string credentials1 = Convert.ToBase64String(Encoding.ASCII.GetBytes(auth_id+ ":")); webRequest.Headers["Authorization"] = "Basic " + credentials1; return webRequest; } } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1007839.html

(0)
上一篇 2021年12月29日
下一篇 2021年12月29日

精彩推荐