locked
Can't get WCF working in WF RRS feed

  • Question

  • Hi everybody,

    In our "old" WF3.5 workflows we invoke some web services using the SendActivity this works fine. At this moment we're in the migration to WF4 but can't get this working. I've several issues with the new SendAndReceiveReply activity.

    Assume we have to following class:

    [ServiceContract]
    public class IMyService
    {
        [OperationContract]
        void SwitchPower(bool powerOn);
    }
    
    

    Step 1
    (without Action)
    On my sequence I've added a new SendAndReceiveReply activity. I always configure the endpoints in the config so the EndpointConfigurationName points to a valid endpoint. No problems so far.

    Here are the other interseting properties:
    OperationName = SwitchPower
    ServiceContractName = MyNamespace.IMyService
    Value = True

    When I run this sequence I get the following exception:
    "The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)."

    Step 2 (with Action)
    So according to the previous exception I've to add an Action to my OperationContract:
    [OperationContract(Action="urn:SwitchPower")]
    void SwitchPower(bool powerOn);
    
    So I modified the Action property of the SendAndReceiveReply activity to match the operationcontract and when I run the sequence this time I get the following exception:
    "Error in deserializing body of request message for operation 'SwitchPower'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'SwitchPower' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'boolean' and namespace 'http://schemas.microsoft.com/2003/10/Serialization/'"

    What's going on here? Normally we don't use the Action property. It looks like the OperationName isn't used by the runtime?? When I change the OperatonName property to something else and leave the Action property to "urn:SwitchPower" I get the same exception.
    Wednesday, October 7, 2009 2:53 PM

All replies

  • Can you try Add Service Reference?

    Adding a service reference in a workflow project will automatically generate proxy activities that you can use directly to access a service in a workflow. The details are encapsulated within the custom activity and the workflow author can focus on the business logic.

    You can also peep into the generated code and look at the right configuration there.

    Hope it helps,
    Andrew
    Thursday, October 8, 2009 6:02 AM
  • It looks like there is a problem in my datacontract.

    For testing purposes only, I created a new solution (Sequential Workflow Console Application) and added an other new project (WCF Service Application) into it. On the "Console" I've added a Service Reference to the newly created "Service" without editing anything. This all works well and I'm able to debug the whole process.

    So further investigation was needed. I've added a new Service Reference to my "old" Service but there seems to be an error in the used DataContract. When removing the DataContract parameters I again faced the exception about the message Action.

    I'm currently investigating the difference between the new projects and my "old" service. I'll keep you informed.
    Thursday, October 8, 2009 7:59 AM
  • When adding a Service Reference VS creates two sequences (GetData.xaml, GetDataUsingDataContract.xaml) and a Reference.cs file.
    In the Reference.cs file everything is wrapped into messagecontracts.

    My server project contains the following code:

    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);
    
        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);
    }


    This is represented in the Reference.cs by:

        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
        [System.ServiceModel.MessageContractAttribute(WrapperName="GetData", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
        public partial class GetDataRequest {
            
            [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
            public int value;
            
            public GetDataRequest() {
            }
            
            public GetDataRequest(int value) {
                this.value = value;
            }
        }



    Why is that? Is is possible to do it without the MessageContracts? We generaly do not use MessageContract because we reference all assemblies so we use. Propably that's the wrong way?

    Thursday, October 8, 2009 9:13 AM
  • Further investigation on using Service References leads me to the following bug. In our datamodel we have some collection classes like the RoutingEntryCollection in this bug.

    Thus, using Service References is imposible at this moment for us. Why should I implement message contracts while using the SendAndReceiveReply activity?

    For the time being I created a custom activity which allows me to access WCF services in the same way we do in some of our applications:

    public class SendActivity<TService, TInput, TOutput> : CodeActivity
    {
        public InArgument<string> EndpointConfigurationName { get; set; }
        public InArgument<string> Operation { get; set; }
        public InArgument<TInput> Input { get; set; }
        public OutArgument<TOutput> Output { get; set; }
    
        protected override void Execute(CodeActivityContext context)
        {
            ChannelFactory<TService> channelFactory = new ChannelFactory<TService>(this.EndpointConfigurationName.Get(context));
            TService service = channelFactory.CreateChannel();
    
            TOutput response = (TOutput)typeof(TService).InvokeMember(
                this.Operation.Get(context),
                BindingFlags.InvokeMethod,
                null,
                service,
                new object[] { this.Input.Get(context) });
    
            context.SetValue<V>(this.Output, response);
        }
    }


    Could someone please provide me with additional information about using the message contracts?
    • Proposed as answer by axorth Wednesday, January 26, 2011 2:52 PM
    Thursday, October 8, 2009 11:53 AM
  • It seems to be a known thing: I came across this blog post a while ago: Using Windows Workflow Foundation 4 Receive from an non WF client.  It's one of a series of posts and in this one he deals with sending messages from a non-WF client to a workflow.  Unfortunately, he doesn't explain why.
    Saturday, October 10, 2009 6:08 AM
  • You can also peep into the generated code and look at the right configuration there.

    Hope it helps,
    Andrew

    It seems that a number of people are digging into the generated code in order to figure out the proper configuration. Should we expect some sort of documentation when the product goes live?

    It works, but i'd really would like to know why i need X and not Y or Z

    Regards,

    Saturday, October 10, 2009 7:40 AM
  • Hi Dutchdre ,
    The bug you mention should be fixed in Beta 2 so I'd like to know if you are using Beta 1 or Beta 2 bits?

    Thanks,
    Amy
    Friday, October 23, 2009 7:21 PM
  • Hi AmyMac,

    I'm currently using Beta 2 the mentioned problem is partially solved. I'm able to send parameters using the send activity but I can't get it working to get the return value back into a variable. 

    When I look at the automatic generated code using "Add Service Reference" I see something like a variable reference. But even using that code I'm not able to get the return value.

    Could you please provide a some information about using the receive activity?

    Friday, October 23, 2009 8:32 PM
  • I have added the service reference then rebuilt both the project and the solution, however I cannot find these proxy activities.  I couldn't find them in beta 1 either.  Where are they supposed to show up and if they dont what can I do to find them?

    Bob
    Saturday, October 24, 2009 7:12 PM
  • Where are they supposed to show up and if they dont what can I do to find them?

    In the Solution Explorer hightlight the project with the service reference. Click the "Show All Files" toolbutton at the top of the Solution Explorer and expand your service reference. The proxy activities are stored in the Reference.svcmap node.
    • Proposed as answer by Dave Cliffe - MSFT Monday, October 26, 2009 10:22 PM
    • Unproposed as answer by Dutchdre Monday, October 26, 2009 10:31 PM
    Monday, October 26, 2009 8:00 AM
  • If you can find them using "Show All Files" (they are the .xaml files under Reference.svcmap), then they should show up in your toolbox after building.  If that's not happening for you, then you can do a manual workaround of right-clicking on the Toolbox and selecting "Choose Items" and then selecting the activities from the System.Activities tab.

    -- Dave
    Monday, October 26, 2009 10:00 PM
  • The point in this thread is not where to find the automatically created activities but how to get it working manual. Beta 2 solved a part of the problem. It is now possible to send parameters through the send activity. There is only one question left: how to get the answer back?
    Monday, October 26, 2009 10:33 PM
  • Hi Dutchdre,

    I cant even send the parameters through the send activity.  Where i get the error "The message with Action '' cannot be processed at the receiver".

    Please help

    Saturday, June 26, 2010 1:07 AM
  • The final version of WF4 this problem still exist. And MS don't give any solution for this
    cokkiy is good boy
    Saturday, August 7, 2010 3:25 AM