Calling a SOAP service in .net Core

前端 未结 7 1910
失恋的感觉
失恋的感觉 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:02

    For those who are trying to do the same with NTLM and .Net Core and wondering what some of the variables are defined as, I clarified the code to look like:

    IAService_PortType is the service reference you created if you followed the guide on https://joshuachini.com/2017/07/13/calling-a-soap-service-from-asp-net-core-or-net-core/

    BasicHttpBinding basicHttpBinding = 
        new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
    // Setting it to Transport will give an exception if the url is not https
    basicHttpBinding.Security.Transport.ClientCredentialType = 
        HttpClientCredentialType.Ntlm;
    
    ChannelFactory factory = 
        new ChannelFactory(basicHttpBinding, 
        new EndpointAddress(
            new Uri("https://someurl.com/ws/TheEndpoint.pub.ws:AService")));
    factory.Credentials.Windows.ClientCredential.Domain = domain;
    factory.Credentials.Windows.ClientCredential.UserName = user;
    factory.Credentials.Windows.ClientCredential.Password = pass;
    IAService_PortType serviceProxy = factory.CreateChannel();
    ((ICommunicationObject)serviceProxy).Open();
    
    try
    {
        var result = serviceProxy.getSomethingAsync("id").Result;
    
    }
    finally
    {
        // cleanup
        factory.Close();
        ((ICommunicationObject)serviceProxy).Close();
    }
    

提交回复
热议问题