locked
Call wcf service from code activity RRS feed

  • Question

  • I want to call wcf service from my workflow. First choice will be to use a Send and Receive Reply activity. However, the parameter values to the operations are extracted from an extension class. As far as I know extensions cannot be accessed from the workflow designer. Or not?

    So I want to call the wcf service from a custom code activity. But; I'm struggling with this. The Add Service Reference utility generates a request and response object per operation. How do I use these in my code activity?

    I was expecting to instantiate the service and call the operation:

    MyService proxy = new MyService();
    proxy.AddQuery(extension.RegNo, extension.AccountNo);
    
    How do I use the request object. Is the following correct:
    AddQueryRequest req = AddQueryRequest()
    {
    RegNo = extension.RegNo,
    AccountId = extension.AccountNo
    };
    
    

     

    So how do I invoke the Request. Where do I catch the response? Am I suppose to create Send and Receive activities within my custom activitty?

    Samples will be great.

     

    Thanks

    Monday, August 23, 2010 11:22 AM

Answers

  • Ok devgal169,

    i understand you troube...

    i always add services my proxy in an other projet. i tryed to hade reference as you and i have the same surpise  : Visual Studio don't generate basic proxy :(

    2 ways to solve it :

    -> Generate proxy in an other assembly and use it

    -> Generate proxy in same project than your workflow and you'll have activities to put in your worklfows

    If you want to use those activities you'll have to drop Proxy activities in your workflow (one activity = one wcf methode)

    Or you could use activities in your code but you'll ahve to code NativeActivity to be able to schedule proxy activities.

     

    To found your activities :

    -> look the toolbox in a workflow designer (after compuling) and you'll see proxy activities

    -> or else in code you can found it in your namespace.ReferenceNamespace.Activities

    In this exemple i have a namespace Demo.WF4.Client and a referenace named : ServiceReference. I have an activity generated that could be use like this :

    Activity a = new Demo.WF4.Client.ServiceReference1.Activities.Hello { name= new InArgument<string>(..) , result = new OutArgument<string>( ...)  };

    I hope it's help ;)


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Monday, August 23, 2010 2:59 PM

All replies

  • Hi devgal,

    Your proxy sould be used as a simple WCF proxy. Activities generated are only for workflows (as composite activity).

    To respect good practice, you should use your proxy in an asynCodeActivity.


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Monday, August 23, 2010 12:22 PM
  • Thanks for your response, Jeremy.

    When I add a service reference it generates request and response objects per operation and the interface. But; it doesn't generate the the client object. If I add service reference to difference project (say a WPF project) it works correctly. Why doesn't it generate the client object for workflow projects as in:

    What type should the proxy be in the snippet below?

    AddQueryRequest req = AddQueryRequest()
    {
    RegNo = extension.RegNo,
    AccountId = extension.AccountNo
    };
    
    IMyService proxy = new ??
    
    proxy.AddQuery(req);
    

    Add Service Reference.. doesn't generate the client object like in the WPF project. 

    MyServiceClient proxy = new MyServiceClient();
    

    Is there an example where a custom activity calls a WCF Service. Sounds silly but I can't get it right.

     

     

     

     

     

     
    Monday, August 23, 2010 1:05 PM
  • Ok devgal169,

    i understand you troube...

    i always add services my proxy in an other projet. i tryed to hade reference as you and i have the same surpise  : Visual Studio don't generate basic proxy :(

    2 ways to solve it :

    -> Generate proxy in an other assembly and use it

    -> Generate proxy in same project than your workflow and you'll have activities to put in your worklfows

    If you want to use those activities you'll have to drop Proxy activities in your workflow (one activity = one wcf methode)

    Or you could use activities in your code but you'll ahve to code NativeActivity to be able to schedule proxy activities.

     

    To found your activities :

    -> look the toolbox in a workflow designer (after compuling) and you'll see proxy activities

    -> or else in code you can found it in your namespace.ReferenceNamespace.Activities

    In this exemple i have a namespace Demo.WF4.Client and a referenace named : ServiceReference. I have an activity generated that could be use like this :

    Activity a = new Demo.WF4.Client.ServiceReference1.Activities.Hello { name= new InArgument<string>(..) , result = new OutArgument<string>( ...)  };

    I hope it's help ;)


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Monday, August 23, 2010 2:59 PM
  • use svcUtil from the .Net Framework command prompt to generate a proxy class for your service, and then add the proxy class to your workflow project.

    You will then be able to reference your service from within a Custom CodeActivity.

    Here is how to do it:

    1) Get the URL of the service that you want to call by right-clicking on it in Visual studio and selecting "View in Browser"

    2) From the .Net Command Prompt enter svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config + URL of your service (without the +)

    3) The result of step 2, will be the generation of two files: a proxy class file named "generatedProxy.cs" and an app.Config file--inside of the generatedProxy.cs file, you will note a partial class "YourServicenameClient"--an instance of this type is what you will use to call your service.

    4) From within your CodeActivity, enter the following code:

    YourServicenameClient proxy = new YourServicenameClient();

    proxy.MethodYouWantToCall();

    5) if you don't already have an <endpoint> defined that points to your service in the web.config, use the one generated by svcUtil--it will be in the app.Config that was generated.

    Note that the files generated by svcUtil can be found in the directory that the .Net Command Prompt is pointing to.

    Note that if your service is changed, you will need to repeat the above process.


    Stanley Tonkonogy

    Friday, April 13, 2012 2:46 AM