locked
Problems getting response from RPC-Encoded Web Service call using generated activities. RRS feed

  • Question

  • I have created a very simple WCF service using the following code in a standard C# console application:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Description;
    
    namespace TestService
    {
       class Program
       {
          static void Main(string[] args)
          {
             ServiceHost host = new ServiceHost(typeof(TestService), new Uri("http://localhost:8009/TestService"));
             ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
             metadataBehavior.HttpGetEnabled = true;
             host.Description.Behaviors.Add(metadataBehavior);
             host.Open();
             Console.ReadLine();
          }
       }
    
       [ServiceContract]
       public class TestService
       {
          [OperationContract]
          [XmlSerializerFormat(Use =   OperationFormatUse.Encoded, Style = OperationFormatStyle.Rpc)]
          public Person GetPerson()
          {
             return new Person() { Name = "Mr. Buggy" };
          }
       }
    
       [DataContract]
       public class Person
       {
          [DataMember]
          public string Name { get; set; }
       }
    }

    The I created a new C# Workflow Console application, and added a service reference to the service above. I rebuilt the project and added the GetPerson activity followed by a WriteLine activity to write out the result returned from the service call. However, the returned string is empty!

    If I remove the XmlSerializerFormat attribute from the service and update the service reference everything works as expected.  How come this does not work when using this attribute?

    As a side note, if I instead use a normal console application as the client and call the web service via Add Service Reference generated client everything works as expected, so it seems to be only workflows that are affected.

    For completeness I include the XAML of the workflow as well:

    <Activity mc:Ignorable="sads sap sap2010" x:Class="WorkflowConsoleApplication1.Workflow1" sap2010:ExpressionActivityEditor.ExpressionActivityEditor="C#" sap2010:WorkflowViewState.IdRef="WorkflowConsoleApplication1.Workflow1_1"
     xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
     xmlns:local="clr-namespace:WorkflowConsoleApplication1.TestService.Activities"
     xmlns:local1="clr-namespace:WorkflowConsoleApplication1.TestService"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:mca="clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities"
     xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
     xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel"
     xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
     xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
     xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
     xmlns:sc="clr-namespace:System.ComponentModel;assembly=System"
     xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
     xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
     xmlns:srs="clr-namespace:System.Runtime.Serialization;assembly=System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <TextExpression.NamespacesForImplementation>
        <sco:Collection x:TypeArguments="x:String">
          <x:String>System</x:String>
          <x:String>System.Collections.Generic</x:String>
          <x:String>System.Data</x:String>
          <x:String>System.Linq</x:String>
          <x:String>System.Text</x:String>
          <x:String>WorkflowConsoleApplication1.TestService</x:String>
        </sco:Collection>
      </TextExpression.NamespacesForImplementation>
      <TextExpression.ReferencesForImplementation>
        <sco:Collection x:TypeArguments="AssemblyReference">
          <AssemblyReference>Microsoft.CSharp</AssemblyReference>
          <AssemblyReference>System</AssemblyReference>
          <AssemblyReference>System.Activities</AssemblyReference>
          <AssemblyReference>System.Core</AssemblyReference>
          <AssemblyReference>System.Data</AssemblyReference>
          <AssemblyReference>System.Runtime.Serialization</AssemblyReference>
          <AssemblyReference>System.ServiceModel</AssemblyReference>
          <AssemblyReference>System.ServiceModel.Activities</AssemblyReference>
          <AssemblyReference>System.Xaml</AssemblyReference>
          <AssemblyReference>System.Xml</AssemblyReference>
          <AssemblyReference>System.Xml.Linq</AssemblyReference>
          <AssemblyReference>mscorlib</AssemblyReference>
          <AssemblyReference>TestClient</AssemblyReference>
        </sco:Collection>
      </TextExpression.ReferencesForImplementation>
      <Sequence sap2010:WorkflowViewState.IdRef="Sequence_1">
        <Sequence.Variables>
          <Variable x:TypeArguments="local1:Person" Name="result" />
        </Sequence.Variables>
        <local:GetPerson sap2010:WorkflowViewState.IdRef="GetPerson_1" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces">
          <local:GetPerson.GetPersonResult>
            <OutArgument x:TypeArguments="local1:Person">
              <mca:CSharpReference x:TypeArguments="local1:Person">result</mca:CSharpReference>
            </OutArgument>
          </local:GetPerson.GetPersonResult>
        </local:GetPerson>
        <WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_1">
          <InArgument x:TypeArguments="x:String">
            <mca:CSharpValue x:TypeArguments="x:String">result.Name</mca:CSharpValue>
          </InArgument>
        </WriteLine>
        <sads:DebugSymbol.Symbol>dzBEOlxQcm9qZWN0c1xUZXN0Q2xpZW50XFRlc3RDbGllbnRcV29ya2Zsb3cxLnhhbWwFLAM9DgIBATAFNhcCAQU3BTsRAgECMwszXAIBBjkJOVICAQM=</sads:DebugSymbol.Symbol>
      </Sequence>
      <sap2010:WorkflowViewState.ViewStateManager>
        <sap2010:ViewStateManager>
          <sap2010:ViewStateData Id="GetPerson_1" sap:VirtualizedContainerService.HintSize="211,22" />
          <sap2010:ViewStateData Id="WriteLine_1" sap:VirtualizedContainerService.HintSize="211,61" />
          <sap2010:ViewStateData Id="Sequence_1" sap:VirtualizedContainerService.HintSize="233,247">
            <sap:WorkflowViewStateService.ViewState>
              <scg:Dictionary x:TypeArguments="x:String, x:Object">
                <x:Boolean x:Key="IsExpanded">True</x:Boolean>
              </scg:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
          </sap2010:ViewStateData>
          <sap2010:ViewStateData Id="WorkflowConsoleApplication1.Workflow1_1" sap:VirtualizedContainerService.HintSize="273,327" />
        </sap2010:ViewStateManager>
      </sap2010:WorkflowViewState.ViewStateManager>
    </Activity>


    Thursday, August 28, 2014 3:10 PM

Answers

  • Well, it looks like a limitation on the Send activity that is used in the workflow-based client.

    It has a SerializerOption property, whose type is System.ServiceModel.Activites.SerializerOption. This SerializerOption type is an enum with the possible values of DataContractSerializer and XmlSerializer.

    If the value of that property is XmlSerializer (as in this case because the service has XmlSerializer specified), the contract inference code inside the workflow runtime creates a default XmlSerializerFormatAttribute for the operation, which has the default values of Style = Document and Use = Literal. There doesn't seem to be a public way to set the Style and Use properties of this XmlSerializerFormatAttribute to make them match your WCF service values of Style = Rpc and Use = Encoded.

    Jim

    • Marked as answer by Peter Palotas Monday, October 13, 2014 11:49 AM
    Friday, September 26, 2014 6:52 PM

All replies

  • Hi,

    please refer to the document which might be helpful to you

    #Windows Workflow Foundation: Calling WCF Services 

    http://www.request-response.com/blog/PermaLink,guid,c3e15d02-a74b-4ed4-a282-925342bdaddc.aspx

    #send and receive activity

    http://msdn.microsoft.com/en-us/library/cc825354.aspx

    Friday, August 29, 2014 8:45 AM
  • I can't find anything particularly in these pages that would explain the problem I'm having?  Also the second link talks about WF 3.5, and my issue is in WF4. Is there something in particular I am missing here?
    Friday, August 29, 2014 8:51 AM
  • Well, it looks like a limitation on the Send activity that is used in the workflow-based client.

    It has a SerializerOption property, whose type is System.ServiceModel.Activites.SerializerOption. This SerializerOption type is an enum with the possible values of DataContractSerializer and XmlSerializer.

    If the value of that property is XmlSerializer (as in this case because the service has XmlSerializer specified), the contract inference code inside the workflow runtime creates a default XmlSerializerFormatAttribute for the operation, which has the default values of Style = Document and Use = Literal. There doesn't seem to be a public way to set the Style and Use properties of this XmlSerializerFormatAttribute to make them match your WCF service values of Style = Rpc and Use = Encoded.

    Jim

    • Marked as answer by Peter Palotas Monday, October 13, 2014 11:49 AM
    Friday, September 26, 2014 6:52 PM
  • Okay, thanks for the response. I guess I will open an issue on Connect for this then.
    Monday, October 13, 2014 11:49 AM
  • Perfect.

    Thanks.

    Jim

    Monday, October 13, 2014 5:14 PM