Step 1: Build and Publish the WCF Service
Step 2: Deploy the WCF Service
Step 3: Create WCF client
Create a WCF client using ServiceModel Metadata Utility Tool (Svcutil.exe) by using following steps:
- On the Start menu click All Programs, and then click Visual Studio 2010. Click Visual Studio Tools and then click Visual Studio 2010 Command Prompt.
- Navigate to the directory where you want to place the client code.
- Use the command-line tool ServiceModel Metadata Utility Tool (Svcutil.exe) with the appropriate switches to create the client code. The following example generates a code file and a configuration file for the service.
svcutil.exe /language:cs /out:TaxServiceClient.cs http://192.168.124.26:81/TaxProductionService
Step 4: Write Plugin to consume external WCF Service
- Add the above generated .CS class into the plugin solution. In Visual Studio, right-click the client project in Solution Explorer and select Add and then Existing Item. Select the TaxServiceClient.cs file generated in the preceding step.
- Open the plugin.cs class from the solution. And call the WCF client using channel factory.
#region Calling WCF Service
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.Name = “BasicHttpBinding_IPOCService”;
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://192.168.124.26:81/TaxProductionService.svc“);
ChannelFactory<IPOCService> factory = new ChannelFactory<IPOCService>(myBinding, endPointAddress);
IPOCService channel = factory.CreateChannel();
taxAmount = channel.GetCalculatedTaxValue(unitPrice);
Step 5: Register the Plugin using registration tool.
You can also download a sample code from below link:
Great Post. Helps a lot!!!
Thank you so much.
I’ve followed this process but on the plugin I get the following error : Business Process Error – Type ‘System.Threading.Tasks.Task`1
[System.Int32]’ cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
Do you have any idea why I am getting this? Is it to do with the fact that my WCF service doesn’t have asynch calls?
Simsie, You need to serialize the WCF service..DataMembers as [Serializable()] in your interface class.
I’ve added Serializable() to my interface class but it hasn’t made a difference. I don’t think it should anyway because the datamemember attribute is serializable anyway. [System.Runtime.Serialization.DataMemberAttribute()]
This has got me stumped. I am setting the step to be synchronous anyway so I don’t see why it should be using Task
Please post interface class of your WCF service and also try it with a simple WCF service..
you may try Generate WCF client proxy with “/syncOnly”
I have tried this but I get a runtime error:
Could not load type ‘System.ServiceModel.HttpBindingBase’ from assembly ‘System.ServiceModel” – The exception message is “Operation could destabilize the runtime.” What am I missing?
Just to confirm KC suggested “you may try Generate WCF client proxy with “/syncOnly” that actually worked for me, and I am writing a plugin to fire from CRM 2013 Online calling an external WCF service.