Connecting to a SOAP service with .Net Core 2.0 be

2020-03-30 02:06发布

I'm using Visual Studio 2017.

I have noticed that it was not possible to connect to a SOAP service from a .Net Core 2.0 when being behind a proxy (when connected directly to the internet it's working and when connecting through the proxy from a .Net Core 1.1 app it's working too).

I have created a little test program (Console app) that calls a public SOAP service (http://www.webservicex.net/globalweather.asmx). By changing the target of this program (.Net Core 1.1 / .Net Core 2.0) I can reproduce the problem.

Here is the sample code (the classes for connecting to the web service have been generated with VS 2017's Connected Services component):

BasicHttpBinding binding = new BasicHttpBinding();

EndpointAddress address = new EndpointAddress("http://www.webservicex.net/globalweather.asmx");

GlobalWeatherSoapClient client = new GlobalWeatherSoapClient(binding, address);

var response = client.GetCitiesByCountryAsync("France").Result;

I have done a network capture (with Wireshark) and when this problem happens I can see no HTTP request coming out from my computer. Does anybody know what is going wrong ? Maybe I am not calling this service the right way.

Thanks in advance

1条回答
放我归山
2楼-- · 2020-03-30 02:34

I had the same problem, no outgoing http requests in Wireshark. The project had to use a corporate proxy with credentials to connect to a https address, thus BasicHttpSecurityMode.Transport was set.

The reason was a bug in .net Core 2.0 with proxy settings. It hasn't used the WinINet (IE/Edge) proxy settings and you wasn't able to configure a separate proxy, more info here https://github.com/dotnet/wcf/issues/1592.

Solution

After upgrading the project to .net Core 2.1, and update System.ServiceModel.Http and other dependcies to latest stable (4.5.3 in my case), the IE/Edge proxy settings are used.

查看更多
登录 后发表回答