简体   繁体   English

无法从IIS托管的应用程序连接到远程REST服务

[英]Unable to connect to the remote REST service from the IIS-hosted application

I have a SOAP web service that is hosted in IIS on my machine. 我的计算机上的IIS中托管了一个SOAP Web服务。 This SOAP service has several methods which may interact with the remote REST service that uses Basic authentication. 此SOAP服务有几种方法可以与使用基本身份验证的远程REST服务进行交互。

I use the following code to make a POST request to the REST service from my SOAP service: 我使用以下代码从SOAP服务向REST服务发出POST请求:

HttpClient serviceClient;
serviceClient = new HttpClient {BaseAddress = new Uri("https://myremoterestservice.com:9981/callme/")};
serviceClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
            "Basic",
            Convert.ToBase64String(
                Encoding.ASCII.GetBytes(
                    $"myuser:mypassword")
            )
        );

string postXml = "my request XML";
Task<HttpResponseMessage> task = serviceClient.PostAsync("methodname", new StringContent(postXml, Encoding.UTF8, "application/xml");
// I need to get the result synchronously
using (var response = task.Result) // exception "A Task was cancelled" thrown here
{
    using (var content = response.Content)
    {
        // ....
    }
}

Everything works with the different remote REST service that uses HTTP. 一切都可以与使用HTTP的不同远程REST服务一起使用。 But when I try to call the same method for the REST service that uses HTTPS, this code throws an exception with the message "A task was cancelled" at the line using (var response = task.Result) 但是,当我尝试为使用HTTPS的REST服务调用相同的方法时,此代码using (var response = task.Result)在行上引发异常,并显示消息“任务已取消”。

But this doesn't work only when I'm calling that code via my SOAP web service - it fails even to establish a connection with the remote REST service. 但这仅在我通过SOAP Web服务调用该代码时不起作用-甚至无法与远程REST服务建立连接。 When I'm calling the same code from my unit-tests, it works. 当我从单元测试中调用相同的代码时,它可以工作。

I think the issue may be somewhere in the IIS settings or in the web.config file of my SOAP web service, but I don't have an idea where exactly. 我认为问题可能出在IIS设置中或我的SOAP Web服务的web.config文件中,但是我不知道确切的位置。

UPDATE: I noticed that TLS 1.2 is used when I'm running this request from my unit-tests in visual studio. 更新:我注意到在Visual Studio的单元测试中运行此请求时使用了TLS 1.2。 When I'm running it from my IIS-hosted SOAP web service, TLS 1.0 is used. 当我从IIS托管的SOAP Web服务运行它时,将使用TLS 1.0。

I decided to compare request that I made using the Visual Studio with the request that was made by the SOAP web-service, and I noticed that there was a difference in a TLS version: TLS 1.2 was used when I run the request using Visual Studio, and the TLS 1.0 was used by the web service. 我决定将使用Visual Studio发出的请求与SOAP Web服务发出的请求进行比较,然后发现TLS版本有所不同:使用Visual Studio运行请求时使用TLS 1.2 ,并且Web服务使用了TLS 1.0。 I found that the issue was in the web.config file of my SOAP web service. 我发现问题出在我的SOAP Web服务的web.config文件中。 The following setting was specified in the web.config: 在web.config中指定了以下设置:

<httpRuntime targetFramework="4.5.2" />

TLS 1.2 was supported by default only since .NET 4.6. 从.NET 4.6开始,默认情况下才支持TLS 1.2。 So, when I changed httpRuntime targetFramework to 4.7, everything started to work. 因此,当我将httpRuntime targetFramework更改为4.7时,一切开始起作用。 It seems that the remote REST service was configured to not allow TLS 1.0 to make a handshake. 似乎将远程REST服务配置为不允许TLS 1.0进行握手。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Linux Web应用程序中使用IIS托管的WCF服务 - Consuming IIS-hosted WCF Service from Linux Web Application IIS托管的WCF REST服务-JSON将枚举序列化为字符串 - IIS-Hosted WCF REST service - JSON serialize enum as string TuesPechkin:IIS 托管的应用程序 - TuesPechkin: IIS-hosted application 从IIS托管的应用程序通过SSL访问Web服务时出错 - Error accessing web service through SSL from IIS-hosted application 使用MS Sync Framework和IIS托管的WCF服务将带有2mb条目的表同步 - Synchronizing table with 2mb entry with MS Sync Framework and IIS-Hosted WCF Service takes 10 minutes 无法使用SQL身份验证从IIS托管应用程序连接到SQL Server数据库 - Unable to connect to SQL Server database from IIS hosted application using SQL authentication 无法解决在原始IIS托管的WCF示例中的错误:找不到作为服务属性值[...]提供的类型[…] - Cannot resolve error in vanilla IIS-hosted WCF example: The type […] provided as the Service attribute value […] could not be found 尝试从IIS中托管的Web应用程序连接到具有命名管道端点的WCF服务时,没有端点侦听错误 - No endpoint listening error when trying to connect to a WCF service with named pipe endpoint from Web application hosted in IIS 应如何将 IIS 托管的基于 ASP.Net 的系统部署到 Azure Service Fabric? - How should IIS-hosted ASP.Net-based systems be deployed to Azure Service Fabric? 如何解决 C# IIS 托管 WCF NET TCP 服务超时问题 - How to troubleshoot C# IIS-hosted WCF NET TCP service timeout issues
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM