Consume an external WCF service from a custom workflow/plugin


AIM: To call an external WCF service from a custom workflowor a plugin.

Since custom workflows and plugins are essentially class libraries, there is no associated config file which can hold the binding details of the WCF service. So, to consume a WCF service, a proxy file needs to be generated using svcutil.exe. This command needs to executed from the command prompt. Now to generate the proxy file, navigate to the location of the svcutil.exe on the machine and execute the following:

svcutil.exe /language:cs /out:proxy.cs /config:app.config http://server:port/servicename.svc

A proxy.cs file is generated at the location of the svcutil.exe. This proxy.cs needs to be included in the workflow or plugin solution.

The binding for the WCF serviceshould be set in the code as follows:

BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.Name = "<Give a Binding Name here>";
myBinding.Security.Mode = BasicHttpSecurityMode.None;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
myBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
EndpointAddress endPointAddress = new EndpointAddress(" http://server:port/servicename.svc");
WCFClient client = new WCFClient(myBinding, endPointAddress);
Theclient’ object will now be able to access the WCF service methods for e.g. client.insertDetails("Parameter_1", " Parameter_2");

3 comments:

  1. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work שרת וירטואלי

    ReplyDelete
  2. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. europa-road.eu

    ReplyDelete
  3. I read your blog frequently and I just thought I’d say keep up the amazing work! recargas y facturas tigo colombia

    ReplyDelete

Popular Posts