Xamarin Android:SOAP Web服务失败(401 Unauthorized)但我的证书是正确的

时间:2016-12-06 11:51:41

标签: soap xamarin xamarin.android unauthorized

Xamarin.Android中的错误

我收到以下错误:

  

{System.Net.WebException:请求失败,HTTP状态为401:   未经授权的   System.Web.Services.Protocols.SoapHttpClientProtocol.ReceiveResponse   (System.Net.WebResponse响应,   System.Web.Services.Protocols.SoapClientMessage消息,   System.Web.Services.Protocols.SoapExtension [] extensions)[0x00055] in   /Users/builder/data/lanes/3511/77cb8568/source/mono/mcs/class/System.Web.Services/System.Web.Services.Protocols/SoapHttpClientProtocol.cs:273   在System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke   (System.String method_name,System.Object [] parameters)[0x000b8] in   /Users/builder/data/lanes/3511/77cb8568/source/mono/mcs/class/System.Web.Services/System.Web.Services.Protocols/SoapHttpClientProtocol.cs:365   在DSPFood.Droid.SOAP.scan.ShipGetNewBatchCode(System.String   scanID)[0x00001]在C:\ Projects \ Projecten \ DSP中   食品\解决方案\ DSPFood \ DSPFood \ DSPFood.Droid \ WEB   引用\ SOAP \ Reference.cs:389 at(包装器   远程-调用,以检查)   DSPFood.Droid.SOAP.scan:ShipGetNewBatchCode(string)at   DSPFood.Droid.DependencyServices.SoapService + d__13.MoveNext   ()[0x00057]在C:\ Projects \ Projecten \ DSP中   食品\解决方案\ DSPFood \ DSPFood \ DSPFood.Droid \ DependencyServices \ SoapService.cs:290   }

控制台应用程序中的工作代码

但是当我在控制台应用程序中运行以下代码时,它可以工作:

static void Main(string[] args)
{
    var nc = new NetworkCredential("**", "**");
    var soapClient = new SOAP.scan();

    soapClient.UseDefaultCredentials = true;
    soapClient.Credentials = nc;
    var response = soapClient.ProdGetNewBatchCode("");
}
  

回复:“A000000086”

Xamarin

public string ShipGetNewBatchCode(string macAddress)
{
    var retValue = "";

    try
    {
        var nc = new NetworkCredential("**", "**");
        var soapClient = new SOAP.scan();

        soapClient.UseDefaultCredentials = true;
        soapClient.Credentials = nc;
        var response = soapClient.ProdGetNewBatchCode("");
    }
    catch (Exception ex)
    {
        throw ex;
    }

    return retValue;
}
  

异常:请求失败,HTTP状态为401:未授权

0 个答案:

没有答案