Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing WCF Services without mex binding

I was wondering how a client project in Visual Studio could reference a WCF service that doesn't have a mex binding. Whenever I remove the default mex binding in any sample WCF service, the client apps cannot find the service and in the auto-generated comments, it's recommended that in production environment, mex binding should be removed. Then how are the client apps supposed to find the service and reference it?

like image 478
user1137993 Avatar asked Dec 27 '22 07:12

user1137993


1 Answers

If you have access to the assemblies which contain the types which define the service contract, operations, and data contracts, then you can just create a proxy on the fly using ChannelFactory. In this instance you would not need to retrieve any service metadata as you already have access to all the information you need to call the service.

For example

// Create service proxy on the fly
var factory = new ChannelFactory<IMyServiceContract>("NameOfMyClientEndpointInConfigFile");
var proxy = factory.CreateChannel();

// Create data contract
var requestDataContract = new MyDataContract();

// Call service operation.
var responseDataContract = proxy.MyServiceOperation(requestDataContract);

It also helps if you have access to the service-side config file so you can copy the endpoint details out of there into your client config.

like image 52
tom redfern Avatar answered Jan 04 '23 12:01

tom redfern