Calling a SOAP service in .net Core

前端 未结 7 1923
失恋的感觉
失恋的感觉 2020-11-28 07:12

I´m porting a .net 4.6.2 code to a .net Core project, that calls a SOAP service. In the new code I´m using C# (because of some config reasons I just can´t r

7条回答
  •  孤独总比滥情好
    2020-11-28 08:01

    You can use the ChannelFactoryclass even in pure dotnet core. It is fairly simple.

    var binding = new BasicHttpsBinding();
    var endpoint = new EndpointAddress(new Uri("https:///SimpleSOAPService.svc"));
    dynamic channelFactory = new ChannelFactory(binding, endpoint);
    var serviceClient = channelFactory.CreateChannel();
    var result = serviceClient.Ping();
    channelFactory.Close();
    

    You can find a working GitHub example here.

    Don't forget to change between BasicHttpBinding and BasicHttpsBinding depending on whether you are using HTTP or HTTPS in the URL.

提交回复
热议问题