我正在写一个本地C#WCF服务。我有它工作正常,除了它需要与https api进行交互的地方。每当我尝试获取/发布到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;
}
当我通过visual studio调试器(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:
答案 0 :(得分:0)
您确定第一次调用不是处置或更改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;