Skip to main content

Hi All,


I am trying to do something for WCF that is already being done for Web service as given on
"How to treat a Web Service-based Reference Event when moving a process definition from one environment to another"



I have added a WCF service reference http://machine1.testdom.local:17041/K2_WCF/Service.svc in a k2 workflow through process reference.


I have added a reference event in the workflow to call the WCF service.The constructor that I have added requires endpoint configuration name and remote address. I have provided the following values.


endpoint configuration name - BasicHttpBinding_IService
remote address - http://machine2.testdom.local:17041/K2_WCF/Service.svc


Notice the only difference is in the machine name. What I intend to do is consume the WCF on machine2 instead of machine2. I am doing this so that I would put this in an environment field which can be picked at the run time so that I dont have to worry about URL while moving from one machine to another (one environment to other).


This compiles and deploys correctly but when I start the workflow process it stops with an error which is shown in the error profile as following:


Could not find endpoint element with name 'BasicHttpBinding_IService' and contract 'K2WorkflowProject1.IService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element


However I am able to refer both the services correctly in a console appiication using the following code:


client = new ServiceClient("BasicHttpBinding_IService" ,"http://machine2.testdom.local:17041/K2_WCF/Service.svc");


Any help would be great.


Regards,
Sharad


P.S. I am using K2 blackpearl on windows server 2008R2



 

Hi Sharad,


Firstly I would like to address the issue you are having with WCF.


WCF is very limited in terms of configuration options (by no fault of K2). Microsoft have not provided a way to embed configuration data in an assembly, and this nearly always causes issues with WCF in class libraries (remember that we are merely generating a class library for you when you add a WCF reference). The only known workaround at the moment is to manually construct the binding and address. The reason your console app works is because WCF can locate the app.config.


In order to have more control over the situation I recommend you write your own class library, and use that as your process reference assembly. I would write a public static method in this assembly and use it to construct instances of your service. This method would create a new instance of BasicHttpBinding, and pass that through to the constructor of your service and return the service. There is a MSDN article with more information on constructing your specific type of binding in code.


However, because you are using BasicHttpBinding you don't actually need to use WCF on the client (i.e. K2 process). If you add the service as the old Web Reference it will work (BasicHttpBinding was designed for interopability with older SOAP technologies like Web References). The old web references do not suffer the same limitations as WCF


The second issue is that we have rewritten the Reference Event for our next update. The version that you are using is plauged with bugs; and one of them is that it does not support environment fields (FYI, it only supports data fields and XML fields). I recommend you skip this tutorial until you can upgrade to our next update - and rather learn the new reference event.


Hope this helps.


- Jonathan


Reply