Click here to Skip to main content
15,885,875 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.3K   2K   72  
This article describes a design, implementation, and usage of custom message mediation activities for a XAML workflow.
<Activity mc:Ignorable="sap sap2010 sads" x:Class="Workflow" 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: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:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib" xmlns:sxl="clr-namespace:System.Xml.Linq;assembly=System.Xml.Linq" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><x:Members><x:Property Name="argument1" Type="InArgument(x:String)" /><x:Property Name="argument2" Type="InArgument(x:String)" /></x:Members><mva:VisualBasic.Settings><x:Null /></mva:VisualBasic.Settings><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.Collections.Generic</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>MessageMediationActivityLibrary</AssemblyReference><AssemblyReference>mscorlib</AssemblyReference><AssemblyReference>System</AssemblyReference><AssemblyReference>System.Core</AssemblyReference><AssemblyReference>System.Xml</AssemblyReference><AssemblyReference>System.Xml.Linq</AssemblyReference><AssemblyReference>PresentationCore</AssemblyReference><AssemblyReference>WindowsBase</AssemblyReference><AssemblyReference>PresentationFramework</AssemblyReference><AssemblyReference>System.Xaml</AssemblyReference></sco:Collection></TextExpression.ReferencesForImplementation><Sequence><Sequence.Variables><Variable x:TypeArguments="p:Message" Name="message" /><Variable x:TypeArguments="x:String" Default="92705" Name="myZipCode" /><Variable x:TypeArguments="x:String" Default="http://wsf.cdyne.com/WeatherWS/Weather.asmx" Name="addressToWS" /><Variable x:TypeArguments="p:Message" Name="response" /><Variable x:TypeArguments="sxl:XElement" Name="result" /><Variable x:TypeArguments="x:String" Name="city" /><Variable x:TypeArguments="x:Int32" Name="temperature" /></Sequence.Variables><rm:CreateMessage 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;tns:GetCityWeatherByZIP xmlns:tns=&quot;http://ws.cdyne.com/WeatherWS/&quot;&gt;&#xD;&#xA;          &lt;tns:ZIP&gt;&#xD;&#xA;            &lt;xsl:value-of select=&quot;$zipcode&quot; /&gt;&#xD;&#xA;          &lt;/tns:ZIP&gt;&#xD;&#xA;        &lt;/tns: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="[message]" MessageVersion="Soap11" SourceUri="http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl;contract=WeatherSoap#GetCityWeatherByZIP#Soap11"><InArgument x:TypeArguments="x:String" x:Key="zipcode">[myZipCode]</InArgument><sap2010:WorkflowViewState.IdRef>CreateMessage_1</sap2010:WorkflowViewState.IdRef></rm:CreateMessage><rm:ShowMessage DisplayName="ShowMessage - Request" MessageInput="[message]" Prompt="zipcode message" ShowMessageBody="True" ShowMessageOn="Console" sap2010:WorkflowViewState.IdRef="ShowMessage_1" /><Sequence DisplayName="Proxy"><Sequence.Variables><Variable x:TypeArguments="p:CorrelationHandle" Name="__handle1" /></Sequence.Variables><p:Send x:Name="__ReferenceID0" Action="*" EndpointAddress="[new Uri(addressToWS)]" OperationName="ProcessMessage" ProtectionLevel="None" ServiceContractName="IGenericContract"><p:Send.CorrelationInitializers><p:RequestReplyCorrelationInitializer CorrelationHandle="[__handle1]" /></p:Send.CorrelationInitializers><p:Send.Endpoint><p:Endpoint><p:Endpoint.Binding><p:BasicHttpBinding Name="basicHttpBinding" /></p:Endpoint.Binding></p:Endpoint></p:Send.Endpoint><p:SendMessageContent DeclaredMessageType="p:Message"><InArgument x:TypeArguments="p:Message">[message]</InArgument></p:SendMessageContent><sap2010:WorkflowViewState.IdRef>Send_1</sap2010:WorkflowViewState.IdRef></p:Send><p:ReceiveReply Request="{x:Reference __ReferenceID0}" Action="*" DisplayName="ReceiveReplyForSend"><p:ReceiveMessageContent DeclaredMessageType="p:Message"><OutArgument x:TypeArguments="p:Message">[response]</OutArgument></p:ReceiveMessageContent><sap2010:WorkflowViewState.IdRef>ReceiveReply_1</sap2010:WorkflowViewState.IdRef></p:ReceiveReply><sap2010:WorkflowViewState.IdRef>Sequence_1</sap2010:WorkflowViewState.IdRef></Sequence><rm:ShowMessage MessageInput="[response]" Prompt="zipcode response" ShowMessageBody="True" ShowMessageOn="Console" sap2010:WorkflowViewState.IdRef="ShowMessage_2" /><rm:XPathMessageInspector Message="[response]" SourceUri="http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl;contract=WeatherSoap#GetCityWeatherByZIP#Soap11" XPath="/s:Envelope/s:Body/tns:GetCityWeatherByZIPResponse/tns:GetCityWeatherByZIPResult"><rm:XPathMessageInspector.Namespaces><x:String x:Key="tns">http://ws.cdyne.com/WeatherWS/</x:String></rm:XPathMessageInspector.Namespaces><rm:XPathMessageInspector.Outputs><OutArgument x:TypeArguments="x:String" x:Key="{}{http://ws.cdyne.com/WeatherWS/}City">[city]</OutArgument><OutArgument x:TypeArguments="x:Int32" x:Key="{}{http://ws.cdyne.com/WeatherWS/}Temperature">[temperature]</OutArgument><OutArgument x:TypeArguments="sxl:XElement" x:Key="_result">[result]</OutArgument></rm:XPathMessageInspector.Outputs><sap2010:WorkflowViewState.IdRef>XPathMessageInspector_1</sap2010:WorkflowViewState.IdRef></rm:XPathMessageInspector><WriteLine Text="[city + &quot;,&quot; + temperature.ToString()]" sap2010:WorkflowViewState.IdRef="WriteLine_1" /><WriteLine Text="[result.ToString()]" sap2010:WorkflowViewState.IdRef="WriteLine_2" /><sap2010:WorkflowViewState.IdRef>Sequence_2</sap2010:WorkflowViewState.IdRef><sads:DebugSymbol.Symbol>dw1DOlxFbXB0eS54YW1sAA==</sads:DebugSymbol.Symbol></Sequence><sap2010:WorkflowViewState.IdRef>Workflow_1</sap2010:WorkflowViewState.IdRef><sap2010:WorkflowViewState.ViewStateManager><sap2010:ViewStateManager><sap2010:ViewStateData Id="CreateMessage_1" sap:VirtualizedContainerService.HintSize="581,49"><sap:WorkflowViewStateService.ViewState><scg:Dictionary x:TypeArguments="x:String, x:Object"><x:Boolean x:Key="IsExpanded">False</x:Boolean><x:Boolean x:Key="IsPinned">False</x:Boolean></scg:Dictionary></sap:WorkflowViewStateService.ViewState></sap2010:ViewStateData><sap2010:ViewStateData Id="ShowMessage_1" sap:VirtualizedContainerService.HintSize="581,22" /><sap2010:ViewStateData Id="Send_1" sap:VirtualizedContainerService.HintSize="255,86" /><sap2010:ViewStateData Id="ReceiveReply_1" sap:VirtualizedContainerService.HintSize="255,86" /><sap2010:ViewStateData Id="Sequence_1" sap:VirtualizedContainerService.HintSize="581,336"><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></scg:Dictionary></sap:WorkflowViewStateService.ViewState></sap2010:ViewStateData><sap2010:ViewStateData Id="ShowMessage_2" sap:VirtualizedContainerService.HintSize="581,22" /><sap2010:ViewStateData Id="XPathMessageInspector_1" sap:VirtualizedContainerService.HintSize="581,49"><sap:WorkflowViewStateService.ViewState><scg:Dictionary x:TypeArguments="x:String, x:Object"><x:Boolean x:Key="IsExpanded">False</x:Boolean><x:Boolean x:Key="IsPinned">False</x:Boolean></scg:Dictionary></sap:WorkflowViewStateService.ViewState></sap2010:ViewStateData><sap2010:ViewStateData Id="WriteLine_1" sap:VirtualizedContainerService.HintSize="581,58" /><sap2010:ViewStateData Id="WriteLine_2" sap:VirtualizedContainerService.HintSize="581,58" /><sap2010:ViewStateData Id="Sequence_2" sap:VirtualizedContainerService.HintSize="603,958"><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="Workflow_1" sap:VirtualizedContainerService.HintSize="643,1038" /></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