从本地WCF服务到https的GET/POST上的SocketException 16010

本文关键字:GET POST 上的 16010 SocketException https WCF 服务 | 更新日期: 2023-09-27 18:20:51

我正在编写一个本地C#WCF服务。我让它工作得很好,除了它需要与httpsapi交互的地方。每当我尝试获取/发布到https时,我都会收到一个socketexception(16010)(适用于http调用)

示例:

    private async void test()
    {
        var client = new System.Net.Http.HttpClient();
        //The next line works just fine, I get a response back
        var r = await client.GetAsync("http://www.google.com/appsstatus/rss/en");
        HttpContent responseContent = r.Content;
        //SOCKETEXCEPTION 16010 at next line
        var r2 = await client.GetAsync("https://www.google.com/appsstatus/rss/en");           
        HttpContent responseContent2 = r2.Content;
    }

当我的服务通过visualstudio调试器(iis-express)运行时,以及当我在本地完整iis服务器上托管服务时,应用程序池在我的凭据上运行时,都会发生这种情况。

我甚至不知道如何开始追逐这个。任何建议都将不胜感激。

异常详细信息:

System.Net.Sockets.SocketException occurred
Message: A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
Additional information: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

使用ServiceStack

             var a = "https://www.google.com/appsstatus/rss/en".GetXmlFromUrl();

我得到以下信息:

System.Net.Sockets.SocketException occurred
  _HResult=-2147467259
  _message=A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
  HResult=-2147467259
  IsTransient=false
  Message=A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 23.21.209.160:443
  Source=System
  ErrorCode=10060
  NativeErrorCode=10060
  StackTrace:
       at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
  InnerException: 

从本地WCF服务到https的GET/POST上的SocketException 16010

您确定您的第一个调用不是在处理或更改client对象的状态吗?你试过这个吗?

var client = new System.Net.Http.HttpClient();
    //The next line works just fine, I get a response back
    var r = await client.GetAsync("http://www.google.com/appsstatus/rss/en");
    HttpContent responseContent = r.Content;
    //SOCKETEXCEPTION 16010 at next line
    client = new System.Net.Http.HttpClient();
    var r2 = await client.GetAsync("https://www.google.com/appsstatus/rss/en");           
    HttpContent responseContent2 = r2.Content;