Click here to Skip to main content
15,881,424 members
Articles / Desktop Programming / XAML

WF4 Custom activities for message mediation

Rate me:
Please Sign up or sign in to vote.
4.98/5 (25 votes)
20 Dec 2012CPOL24 min read 108.1K   2K   72  
This article describes a design, implementation, and usage of custom message mediation activities for a XAML workflow.
<Activity mc:Ignorable="sads sap sap2010" x:Class="EmptyActivity" mva:VisualBasic.Settings="{x:Null}" sap2010:WorkflowViewState.IdRef="EmptyActivity_1" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:rm="clr-namespace:RKiss.MessageMediationActivityLibrary;assembly=MessageMediationActivityLibrary" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Core" xmlns:s3="clr-namespace:System;assembly=System.ServiceModel" xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities" 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:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib" xmlns:ssa="clr-namespace:System.ServiceModel.Activities;assembly=System.ServiceModel.Activities" xmlns:ssc="clr-namespace:System.ServiceModel.Channels;assembly=System.ServiceModel.Channels" xmlns:ssc1="clr-namespace:System.ServiceModel.Channels;assembly=System.ServiceModel" xmlns:ssc2="clr-namespace:System.ServiceModel.Channels;assembly=System.ServiceModel.Web" xmlns:ssd="clr-namespace:System.ServiceModel.Dispatcher;assembly=System.ServiceModel" xmlns:sx="clr-namespace:System.Xml;assembly=System.Xml" xmlns:sx1="clr-namespace:System.Xml;assembly=System.Runtime.Serialization" xmlns:sx2="clr-namespace:System.Xml;assembly=System.Data" xmlns:sxl="clr-namespace:System.Xml.Linq;assembly=System.Xml.Linq" xmlns:sxs="clr-namespace:System.Xml.Serialization;assembly=System.Xml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><TextExpression.NamespacesForImplementation><sco:Collection x:TypeArguments="x:String"><x:String>System.Activities</x:String><x:String>System.Activities.XamlIntegration</x:String><x:String>System.Activities.Statements</x:String><x:String>System.Activities.Expressions</x:String><x:String>System.Activities.Validation</x:String><x:String>Microsoft.VisualBasic.Activities</x:String><x:String>System.ServiceModel</x:String><x:String>System.ServiceModel.Activities</x:String><x:String>System.ServiceModel.Channels</x:String><x:String>System.ServiceModel.Description</x:String><x:String>System.ServiceModel.Security</x:String><x:String>RKiss.MessageMediationActivityLibrary</x:String><x:String>System</x:String><x:String>System.Activities.Debugger.Symbol</x:String><x:String>System.Collections.Generic</x:String><x:String>System.ServiceModel.Dispatcher</x:String><x:String>System.Xml</x:String><x:String>System.Xml.Linq</x:String><x:String>System.Xml.Serialization</x:String><x:String>System.Windows.Markup</x:String></sco:Collection></TextExpression.NamespacesForImplementation><TextExpression.ReferencesForImplementation><sco:Collection x:TypeArguments="AssemblyReference"><AssemblyReference>System.Activities</AssemblyReference><AssemblyReference>System.ServiceModel.Activities</AssemblyReference><AssemblyReference>System.ServiceModel</AssemblyReference><AssemblyReference>System.ServiceModel.Channels</AssemblyReference><AssemblyReference>MessageMediationActivityLibrary</AssemblyReference><AssemblyReference>mscorlib</AssemblyReference><AssemblyReference>System</AssemblyReference><AssemblyReference>System.Core</AssemblyReference><AssemblyReference>System.ServiceModel.Web</AssemblyReference><AssemblyReference>System.Xml</AssemblyReference><AssemblyReference>System.Runtime.Serialization</AssemblyReference><AssemblyReference>System.Data</AssemblyReference><AssemblyReference>System.Xml.Linq</AssemblyReference><AssemblyReference>PresentationCore</AssemblyReference><AssemblyReference>WindowsBase</AssemblyReference><AssemblyReference>PresentationFramework</AssemblyReference><AssemblyReference>System.Xaml</AssemblyReference></sco:Collection></TextExpression.ReferencesForImplementation><Sequence DisplayName="Sequence Test" sap2010:WorkflowViewState.IdRef="Sequence_1" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces"><Sequence.Variables><Variable x:TypeArguments="x:String" Name="zipcode" /><Variable x:TypeArguments="p:Message" Name="request" /><Variable x:TypeArguments="p:Message" Name="response" /><Variable x:TypeArguments="p:CorrelationHandle" x:Name="__ReferenceID0" Name="__handle1" /><Variable x:TypeArguments="sxl:XElement" Name="result" /></Sequence.Variables><Assign sap2010:WorkflowViewState.IdRef="Assign_1"><Assign.To><OutArgument x:TypeArguments="x:String">[zipcode]</OutArgument></Assign.To><Assign.Value><InArgument x:TypeArguments="x:String">92705</InArgument></Assign.Value></Assign><rm:CreateMessage sap2010:Annotation.AnnotationText="Create message based on the web service wsdl metadata" sap2010:WorkflowViewState.IdRef="CreateMessage_1" Mediator="[&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;&#xD;&#xA;  &lt;xsl:output method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; indent=&quot;yes&quot; omit-xml-declaration=&quot;yes&quot; /&gt;&#xD;&#xA;  &lt;xsl:param name=&quot;zipcode&quot; /&gt;&#xD;&#xA;  &lt;xsl:template match=&quot;/&quot;&gt;&#xD;&#xA;    &lt;s11:Envelope xmlns:s11=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xslt=&quot;out&quot;&gt;&#xD;&#xA;      &lt;s11:Header&gt;&#xD;&#xA;        &lt;a:Action s11:mustUnderstand=&quot;1&quot; xmlns:a=&quot;http://schemas.microsoft.com/ws/2005/05/addressing/none&quot;&gt;http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP&lt;/a:Action&gt;&#xD;&#xA;      &lt;/s11:Header&gt;&#xD;&#xA;      &lt;s11:Body&gt;&#xD;&#xA;        &lt;GetCityWeatherByZIP xmlns=&quot;http://ws.cdyne.com/WeatherWS/&quot;&gt;&#xD;&#xA;          &lt;ZIP&gt;&#xD;&#xA;            &lt;xsl:value-of select=&quot;$zipcode&quot; /&gt;&#xD;&#xA;          &lt;/ZIP&gt;&#xD;&#xA;        &lt;/GetCityWeatherByZIP&gt;&#xD;&#xA;      &lt;/s11:Body&gt;&#xD;&#xA;    &lt;/s11:Envelope&gt;&#xD;&#xA;  &lt;/xsl:template&gt;&#xD;&#xA;&lt;/xsl:stylesheet&gt;]" Message="[request]" MessageVersion="Soap11" SourceUri="http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl;contract=WeatherSoap#GetCityWeatherByZIP#Soap11"><InArgument x:TypeArguments="x:String" x:Key="zipcode">[zipcode]</InArgument></rm:CreateMessage><p:Send x:Name="__ReferenceID1" Action="*" sap2010:Annotation.AnnotationText="request message to the web service" sap2010:WorkflowViewState.IdRef="Send_1" OperationName="ProcessMessage" ServiceContractName="IGenericContract"><p:Send.CorrelationInitializers><p:RequestReplyCorrelationInitializer><p:RequestReplyCorrelationInitializer.CorrelationHandle><InArgument x:TypeArguments="p:CorrelationHandle"><VariableValue x:TypeArguments="p:CorrelationHandle" Variable="{x:Reference __ReferenceID0}" /></InArgument></p:RequestReplyCorrelationInitializer.CorrelationHandle></p:RequestReplyCorrelationInitializer></p:Send.CorrelationInitializers><p:Send.Endpoint><p:Endpoint AddressUri="http://wsf.cdyne.com/WeatherWS/Weather.asmx"><p:Endpoint.Binding><p:BasicHttpBinding Name="basicHttpBinding" /></p:Endpoint.Binding></p:Endpoint></p:Send.Endpoint><p:SendMessageContent><InArgument x:TypeArguments="p:Message">[request]</InArgument></p:SendMessageContent></p:Send><p:ReceiveReply Request="{x:Reference __ReferenceID1}" Action="*" sap2010:Annotation.AnnotationText="response from the web service" DisplayName="ReceiveReplyForSend" sap2010:WorkflowViewState.IdRef="ReceiveReply_1"><p:ReceiveMessageContent><OutArgument x:TypeArguments="p:Message">[response]</OutArgument></p:ReceiveMessageContent></p:ReceiveReply><rm:Transform sap2010:Annotation.AnnotationText="Transform response from the web service" DisplayName="Transform " sap2010:WorkflowViewState.IdRef="Transform_1" Input="[XElement.Load(response.GetReaderAtBodyContents.ReadSubTree)]" Mediator="[&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;&#xD;&#xA;  &lt;xsl:output method=&quot;xml&quot; encoding=&quot;utf-8&quot; indent=&quot;no&quot; /&gt;&#xD;&#xA;  &lt;xsl:template match=&quot;/&quot;&gt;&#xD;&#xA;    &lt;xsl:copy-of select=&quot;*&quot; /&gt;&#xD;&#xA;  &lt;/xsl:template&gt;&#xD;&#xA;&lt;/xsl:stylesheet&gt;]" Output="[result]" /><WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_1" Text="[result.ToString]" /><sads:DebugSymbol.Symbol></sads:DebugSymbol.Symbol></Sequence><sap2010:WorkflowViewState.ViewStateManager><sap2010:ViewStateManager><sap2010:ViewStateData Id="Assign_1" sap:VirtualizedContainerService.HintSize="581,60" /><sap2010:ViewStateData Id="CreateMessage_1" sap:VirtualizedContainerService.HintSize="581,295"><sap:WorkflowViewStateService.ViewState><scg:Dictionary x:TypeArguments="x:String, x:Object"><x:Boolean x:Key="IsExpanded">True</x:Boolean><x:Boolean x:Key="IsPinned">False</x:Boolean><x:Boolean x:Key="IsAnnotationDocked">True</x:Boolean></scg:Dictionary></sap:WorkflowViewStateService.ViewState></sap2010:ViewStateData><sap2010:ViewStateData Id="Send_1" sap:VirtualizedContainerService.HintSize="581,106"><sap:WorkflowViewStateService.ViewState><scg:Dictionary x:TypeArguments="x:String, x:Object"><x:Boolean x:Key="IsAnnotationDocked">True</x:Boolean></scg:Dictionary></sap:WorkflowViewStateService.ViewState></sap2010:ViewStateData><sap2010:ViewStateData Id="ReceiveReply_1" sap:VirtualizedContainerService.HintSize="581,106"><sap:WorkflowViewStateService.ViewState><scg:Dictionary x:TypeArguments="x:String, x:Object"><x:Boolean x:Key="IsAnnotationDocked">True</x:Boolean></scg:Dictionary></sap:WorkflowViewStateService.ViewState></sap2010:ViewStateData><sap2010:ViewStateData Id="Transform_1" sap:VirtualizedContainerService.HintSize="581,162"><sap:WorkflowViewStateService.ViewState><scg:Dictionary x:TypeArguments="x:String, x:Object"><x:Boolean x:Key="IsAnnotationDocked">False</x:Boolean></scg:Dictionary></sap:WorkflowViewStateService.ViewState></sap2010:ViewStateData><sap2010:ViewStateData Id="WriteLine_1" sap:VirtualizedContainerService.HintSize="581,60" /><sap2010:ViewStateData Id="Sequence_1" sap:VirtualizedContainerService.HintSize="603,1113"><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="EmptyActivity_1" sap:VirtualizedContainerService.HintSize="643,1193" /></sap2010:ViewStateManager></sap2010:WorkflowViewState.ViewStateManager></Activity>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions