Create WCF endpoint configurations in the client app, in code?

后端 未结 2 918
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 15:40

I am trying to consume a WCF web service from a .NET client application, and I think I need to be able to programmatically create endpoints, but I don\'t know how. I think I

2条回答
  •  失恋的感觉
    2020-12-05 15:50

    An east way to consume a WCF service if you have a reference to the assembly which defines the interface, is using the System.ServiceModel.ChannelFactory class.

    For example, if you would like to use BasicHttpBinding:

    var emailService = ChannelFactory.CreateChannel(new BasicHttpBinding(), new EndpointAddress(new Uri("http://some-uri-here.com/));
    

    If you don't have a reference to the service assembly, then you can use one of the overloaded constructors on the generated proxy class to specify binding settings.

提交回复
热议问题