It think you only need to create this :
// Sample service
public class Service : IService
{
public void SendMessage(string message)
{
// do the processing....
}
}
// Creating client connection using factory
// I can't remember the used of my asterisk here but this is use to identity the configuration name used for the endpoint.
var result = new ChannelFactory<IService>("*", new EndpointAddress(serviceAddress));
IService yourService = result.CreateChannel();
// This will automatically open a connection for you.
yourService.SendMessage("It works!");
// Close connection
result.Close();
Just a bit of my client configuration with multiple endpoints:
<client>
<!--note that there is no address on the endpoints as it will be overridden by the app anyway-->
<endpoint binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" behaviorConfiguration="standardBehavior" contract="IService" name="Service"/>
.
.
</client>
I used this approach to my client to connect with 30+ services hosted in IIS. By the way, I just grab this code to my existing WCF services and the actual implementation of it was, ChannetFactory it wrapper to another method where I could just simply pass my Service as Generic Type and Service Addressess.
I used message pattern Request Reply and .Net 4.5 here.