Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 身份验证失败,因为远程方在从webservice获取响应时已关闭传输流异常_C#_Web Services_Windows Authentication_Httpwebresponse - Fatal编程技术网

C# 身份验证失败,因为远程方在从webservice获取响应时已关闭传输流异常

C# 身份验证失败,因为远程方在从webservice获取响应时已关闭传输流异常,c#,web-services,windows-authentication,httpwebresponse,C#,Web Services,Windows Authentication,Httpwebresponse,我正在呼叫第三方服务,当我请求响应时,它抛出一个异常,该异常表示 “身份验证失败,因为远程方已关闭传输流异常” 我认为在发送凭证时存在问题。我甚至尝试提供新的证书。这是完整的代码 string get_url = "https://**.*******.com/com/******/webservices/public_webservice.cfc?wsdl&Method=CreateUser&SiteID=**&WSPassword=******&UserNam

我正在呼叫第三方服务,当我请求响应时,它抛出一个异常,该异常表示

“身份验证失败,因为远程方已关闭传输流异常”

我认为在发送凭证时存在问题。我甚至尝试提供新的证书。这是完整的代码

string get_url = "https://**.*******.com/com/******/webservices/public_webservice.cfc?wsdl&Method=CreateUser&SiteID=**&WSPassword=******&UserName=******";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(get_url);
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;
request.Credentials = CredentialCache.DefaultCredentials;
//request.UseDefaultCredentials = false;
//request.Credentials = new System.Net.NetworkCredential("*****", "*****");
request.ContentType = "application/x-www-form-urlencoded; charset=ISO-8859-1";

// Show the sent stream
//lbl_send_stream.Text = send_stream;
//lbl_send_stream.Text = get_url;
// Get UserId And LoginToken From Third Party DB
// ==============================================
//Exception gets throwed When code hits here
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

我找到了答案,因为我们调用的第三方Web服务不支持TLS 1.0,它们支持1.1和1.2。所以我不得不改变安全协议

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

我只使用TLS1.2有一个限制,而且资源地址(URL/地址)是本地的。所以上面的解决方案对我不起作用。在仔细分析web.config之后,我尝试使用
作为本地URL,奇迹发生了

<system.net>
    <defaultProxy>
      <proxy usesystemdefault="false" proxyaddress="<yourproxyaddress>" bypassonlocal="true" />
      <bypasslist>  
        <add address="[a-z]+\.abcd\.net\.au$" />  
      </bypasslist>
    </defaultProxy>
</system.net>


请注意,我已经在使用
设置来访问其他外部URL,因此也不允许没有此设置。希望这有帮助

我试过了,但没有解决问题。您可以在从请求获取HTTPResponse之前添加可能的副本。我的SecurityProtocolType没有显示Tls12和Tls11的选项。我正在使用.net framework 4..net 4.0不了解Tls11和Tls12。要访问这些文件,您需要使用.Net 4.5或更高版本。如果使用.Net 4.0,您可以使用TLS1.2
ServicePointManager.SecurityProtocol=(SecurityProtocolType)3072的数值另请参阅其他选项和框架。如果我在尝试使用CMD生成代码时遇到此错误,您有什么意见吗?