WCF: Visual Studio C# Code Snippets for Windows Communication Foundation

by Stephen Horsfield 6. May 2008 17:07

Overview

Following my earlier post about WCF service design guidelines, I've created some WCF code snippets to simplify the implementation of services, operations, messages and data contracts.

Resources

Download the snippet here:

(note that you will need to save the file with the .snippet extension; I've had to rename the extension for this server) 

Content

I've included the full content here, partly to support searches:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <!-- wcf-service-contract -->
    <CodeSnippet Format="1.0.0">
        <Header>
            <Author>Stephen Horsfield</Author>
            <Description>This snippet creates a basic WCF service contract outline</Description>
            <Keywords>
                <Keyword>WCF</Keyword>
                <Keyword>Service</Keyword>
                <Keyword>Contract</Keyword>
            </Keywords>
            <Shortcut>wcf-service-contract</Shortcut>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
            <Title>wcf-service-contract</Title>
        </Header>
        <Snippet>
            <References>
                <Reference>
                    <Assembly>System.ServiceModel.dll</Assembly>
                </Reference>
                <Reference>
                    <Assembly>System.Runtime.Serialization.dll</Assembly>
                </Reference>
            </References>
            <Declarations>
                <Literal>
                    <ID>NS</ID>
                    <ToolTip>The CLR namespace of the interface definition</ToolTip>
                    <Default>ServiceContracts</Default>
                </Literal>
                <Literal>
                    <ID>ServiceClassName</ID>
                    <ToolTip>Name the service</ToolTip>
                    <Default>ServiceContract</Default>
                </Literal>
                <Literal>
                    <ID>Namespace</ID>
                    <ToolTip>The namespace of the service</ToolTip>
                    <Default>urn:tempuri.org/services/</Default>
                </Literal>
                <Literal>
                    <ID>ProtectionLevel</ID>
                    <ToolTip>The minimum ProtectionLevel of the service</ToolTip>
                    <Default>None</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>PL</ID>
                    <Function>SimpleTypeName(global::System.Net.Security.ProtectionLevel)</Function>
                    <Default>global::System.Net.Security.ProtectionLevel</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>SM</ID>
                    <Function>SimpleTypeName(global::System.ServiceModel.SessionMode)</Function>
                    <Default>global::System.ServiceModel.SessionMode</Default>
                </Literal>
                <Literal>
                    <ID>SessionMode</ID>
                    <ToolTip>The session mode of the service</ToolTip>
                    <Type>System.ServiceModel.SessionMode</Type>
                    <Default>Allowed</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>sysSvcContract</ID>
                    <Function>SimpleTypeName(global::System.ServiceModel.ServiceContractAttribute)</Function>
                </Literal>
                <Literal>
                    <ID>access</ID>
                    <Default>public</Default>
                </Literal>
            </Declarations>
            <Code Kind="file" Language="CSharp">
    <![CDATA[/*
  $NS$.$ServiceClassName$
  
  This is a Windows Communication Foundation Service Contract definition for:
  
  Service:   $ServiceClassName$
  Namespace: $Namespace$$ServiceClassName$
*/
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Net.Security;
using System.Runtime.Serialization;
using System.Xml;

namespace $NS$ {

    /// <summary>
    /// $ServiceClassName$ is a Windows Communication Foundation service contract.
    /// The contract definition is defined as follows:
    /// 
    /// Name:             $ServiceClassName$
    /// Namespace:        $Namespace$$ServiceClassName$
    /// Session Mode:     $SessionMode$
    /// Protection Level: $ProtectionLevel$
    /// </summary>
    [$sysSvcContract$(
        Name="$ServiceClassName$",
        Namespace="$Namespace$$ServiceClassName$",
        ProtectionLevel=$PL$.$ProtectionLevel$,
        SessionMode=$SM$.$SessionMode$
        )]
    $access$ interface $ServiceClassName$
    {

    }
}                
                ]]>
            </Code>
        </Snippet>
    </CodeSnippet>
    <!-- wcf-service-contract-duplex -->
    <CodeSnippet Format="1.0.0">
        <Header>
            <Author>Stephen Horsfield</Author>
            <Description>This snippet creates a duplexed pair of WCF service contract outlines</Description>
            <Keywords>
                <Keyword>WCF</Keyword>
                <Keyword>Service</Keyword>
                <Keyword>Contract</Keyword>
            </Keywords>
            <Shortcut>wcf-service-contract-duplex</Shortcut>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
            <Title>wcf-service-contract-duplex</Title>
        </Header>
        <Snippet>
            <References>
                <Reference>
                    <Assembly>System.ServiceModel.dll</Assembly>
                </Reference>
                <Reference>
                    <Assembly>System.Runtime.Serialization.dll</Assembly>
                </Reference>
            </References>
            <Declarations>
                <Literal>
                    <ID>NS</ID>
                    <ToolTip>The CLR namespace of the interface definition</ToolTip>
                    <Default>ServiceContracts</Default>
                </Literal>
                <Literal>
                    <ID>ServiceClassName</ID>
                    <ToolTip>Name the service</ToolTip>
                    <Default>ServiceContract</Default>
                </Literal>
                <Literal>
                    <ID>Namespace</ID>
                    <ToolTip>The namespace of the service</ToolTip>
                    <Default>urn:tempuri.org/services/</Default>
                </Literal>
                <Literal>
                    <ID>ProtectionLevel</ID>
                    <ToolTip>The minimum ProtectionLevel of the service</ToolTip>
                    <Type>global::System.Net.Security.ProtectionLevel</Type>
                    <Default>None</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>PL</ID>
                    <Function>SimpleTypeName(global::System.Net.Security.ProtectionLevel)</Function>
                    <Default>global::System.Net.Security.ProtectionLevel</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>SM</ID>
                    <Function>SimpleTypeName(global::System.ServiceModel.SessionMode)</Function>
                    <Default>global::System.ServiceModel.SessionMode</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>sysSvcContract</ID>
                    <Function>SimpleTypeName(global::System.ServiceModel.ServiceContractAttribute)</Function>
                </Literal>
                <Literal>
                    <ID>access</ID>
                    <Default>public</Default>
                </Literal>
            </Declarations>
            <Code Kind="file" Language="CSharp">
                <![CDATA[/*
  $NS$.$ServiceClassName$
  
  This is a Windows Communication Foundation Service Contract definition for a duplex pair
  of services:
  
  Services:  $ServiceClassName$, $ServiceClassName$Callback
  Namespace: $Namespace$$ServiceClassName$
*/
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Net.Security;
using System.Runtime.Serialization;
using System.Xml;

namespace $NS$ {

    /// <summary>
    /// $ServiceClassName$ is a Windows Communication Foundation service contract.
    /// Together with $ServiceClassName$Callback these form a duplex pair.
    /// The contract definition is defined as follows:
    /// 
    /// Name:              $ServiceClassName$
    /// Namespace:         $Namespace$$ServiceClassName$
    /// Session Mode:      Required
    /// Protection Level:  $ProtectionLevel$
    /// Callback Contract: $ServiceClassName$Callback
    /// </summary>
    [$sysSvcContract$(
        Name="$ServiceClassName$",
        Namespace="$Namespace$$ServiceClassName$",
        ProtectionLevel=$PL$.$ProtectionLevel$,
        SessionMode=$SM$.Required,
        CallbackContract=typeof($ServiceClassName$Callback)
        )]
    $access$ interface $ServiceClassName$
    {

    }

    /// <summary>
    /// $ServiceClassName$Callback is a Windows Communication Foundation service
    /// contract. Together with $ServiceClassName$ these form a duplex pair.
    /// The contract definition is defined as follows:
    /// 
    /// Name:              $ServiceClassName$Callback
    /// Namespace:         $Namespace$$ServiceClassName$
    /// Session Mode:      Required
    /// Protection Level:  $ProtectionLevel$
    /// Primary Contract:  $ServiceClassName$
    /// </summary>
    [$sysSvcContract$(
        Name="$ServiceClassName$",
        Namespace="$Namespace$$ServiceClassName$",
        ProtectionLevel=$PL$.$ProtectionLevel$,
        SessionMode=$SM$.Required
        )]
    $access$ interface $ServiceClassName$Callback
    {

    }
}                
                ]]>
            </Code>
        </Snippet>
    </CodeSnippet>
    <!-- wcf-service-contract-fullduplex -->
    <CodeSnippet Format="1.0.0">
        <Header>
            <Author>Stephen Horsfield</Author>
            <Description>This snippet creates a fully duplexed pair of WCF service contract outlines</Description>
            <Keywords>
                <Keyword>WCF</Keyword>
                <Keyword>Service</Keyword>
                <Keyword>Contract</Keyword>
            </Keywords>
            <Shortcut>wcf-service-contract-fullduplex</Shortcut>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
            <Title>wcf-service-contract-fullduplex</Title>
        </Header>
        <Snippet>
            <References>
                <Reference>
                    <Assembly>System.ServiceModel.dll</Assembly>
                </Reference>
                <Reference>
                    <Assembly>System.Runtime.Serialization.dll</Assembly>
                </Reference>
            </References>
            <Declarations>
                <Literal>
                    <ID>NS</ID>
                    <ToolTip>The CLR namespace of the interface definition</ToolTip>
                    <Default>ServiceContracts</Default>
                </Literal>
                <Literal>
                    <ID>ServiceClassName</ID>
                    <ToolTip>Name the service</ToolTip>
                    <Default>ServiceContract</Default>
                </Literal>
                <Literal>
                    <ID>Namespace</ID>
                    <ToolTip>The namespace of the service</ToolTip>
                    <Default>urn:tempuri.org/services/</Default>
                </Literal>
                <Literal>
                    <ID>ProtectionLevel</ID>
                    <ToolTip>The minimum ProtectionLevel of the service</ToolTip>
                    <Type>global::System.Net.Security.ProtectionLevel</Type>
                    <Default>None</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>PL</ID>
                    <Function>SimpleTypeName(global::System.Net.Security.ProtectionLevel)</Function>
                    <Default>global::System.Net.Security.ProtectionLevel</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>SM</ID>
                    <Function>SimpleTypeName(global::System.ServiceModel.SessionMode)</Function>
                    <Default>global::System.ServiceModel.SessionMode</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>sysSvcContract</ID>
                    <Function>SimpleTypeName(global::System.ServiceModel.ServiceContractAttribute)</Function>
                </Literal>
                <Literal>
                    <ID>access</ID>
                    <Default>public</Default>
                </Literal>
            </Declarations>
            <Code Kind="file" Language="CSharp">
                <![CDATA[/*
  $NS$.$ServiceClassName$
  
  This is a Windows Communication Foundation Service Contract definition for a 
  full duplex pair of services:
  
  Services:  $ServiceClassName$, $ServiceClassName$Callback
  Namespace: $Namespace$$ServiceClassName$
*/
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Net.Security;
using System.Runtime.Serialization;
using System.Xml;

namespace $NS$ {

    /// <summary>
    /// $ServiceClassName$ is a Windows Communication Foundation service contract.
    /// Together with $ServiceClassName$Callback these form a full duplex pair.
    /// The contract definition is defined as follows:
    /// 
    /// Name:              $ServiceClassName$
    /// Namespace:         $Namespace$$ServiceClassName$
    /// Session Mode:      Required
    /// Protection Level:  $ProtectionLevel$
    /// Callback Contract: $ServiceClassName$Callback
    /// </summary>
    [$sysSvcContract$(
        Name="$ServiceClassName$",
        Namespace="$Namespace$$ServiceClassName$",
        ProtectionLevel=$PL$.$ProtectionLevel$,
        SessionMode=$SM$.Required,
        CallbackContract=typeof($ServiceClassName$Callback)
        )]
    $access$ interface $ServiceClassName$
    {

    }

    /// <summary>
    /// $ServiceClassName$Callback is a Windows Communication Foundation service
    /// contract. Together with $ServiceClassName$ these form a duplex pair.
    /// The contract definition is defined as follows:
    /// 
    /// Name:              $ServiceClassName$Callback
    /// Namespace:         $Namespace$$ServiceClassName$
    /// Session Mode:      Required
    /// Protection Level:  $ProtectionLevel$
    /// Callback Contract:  $ServiceClassName$
    /// </summary>
    [$sysSvcContract$(
        Name="$ServiceClassName$",
        Namespace="$Namespace$$ServiceClassName$",
        ProtectionLevel=$PL$.$ProtectionLevel$,
        SessionMode=$SM$.Required,
        CallbackContract=typeof($ServiceClassName$)
        )]
    $access$ interface $ServiceClassName$Callback
    {

    }
}                
                ]]>
            </Code>
        </Snippet>
    </CodeSnippet>
    <!-- wcf-usings -->
    <CodeSnippet Format="1.0.0">
        <Header>
            <Author>Stephen Horsfield</Author>
            <Description>This snippet inserts a set of WCF-related 'using' statements</Description>
            <Keywords>
                <Keyword>WCF</Keyword>
                <Keyword>namespaces</Keyword>
            </Keywords>
            <Shortcut>wcf-usings</Shortcut>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
            <Title>wcf-usings</Title>
        </Header>
        <Snippet>
            <References>
                <Reference>
                    <Assembly>System.ServiceModel.dll</Assembly>
                </Reference>
                <Reference>
                    <Assembly>System.Runtime.Serialization.dll</Assembly>
                </Reference>
            </References>
            <Code Kind="any" Language="CSharp">
                <![CDATA[using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Net.Security;
using System.Runtime.Serialization;
using System.Xml;
]]>
            </Code>
        </Snippet>
    </CodeSnippet>
    <!-- wcf-op-contract -->
    <CodeSnippet Format="1.0.0">
        <Header>
            <Author>Stephen Horsfield</Author>
            <Description>This snippet creates a basic WCF operation contract outline</Description>
            <Keywords>
                <Keyword>WCF</Keyword>
                <Keyword>Operation</Keyword>
                <Keyword>Contract</Keyword>
            </Keywords>
            <Shortcut>wcf-op-contract</Shortcut>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
            <Title>wcf-op-contract</Title>
        </Header>
        <Snippet>
            <References>
                <Reference>
                    <Assembly>System.ServiceModel.dll</Assembly>
                </Reference>
                <Reference>
                    <Assembly>System.Runtime.Serialization.dll</Assembly>
                </Reference>
            </References>
            <Declarations>
                <Literal>
                    <ID>Namespace</ID>
                    <ToolTip>The namespace of the service</ToolTip>
                    <Default>urn:tempuri.org/services/</Default>
                </Literal>
                <Literal>
                    <ID>ProtectionLevel</ID>
                    <ToolTip>The minimum ProtectionLevel of the service</ToolTip>
                    <Default>None</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>PL</ID>
                    <Function>SimpleTypeName(global::System.Net.Security.ProtectionLevel)</Function>
                    <Default>global::System.Net.Security.ProtectionLevel</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>sysOpContract</ID>
                    <Function>SimpleTypeName(global::System.ServiceModel.OperationContractAttribute)</Function>
                </Literal>
                <Literal>
                    <ID>access</ID>
                    <Default>public</Default>
                </Literal>
                <Literal Editable="true">
                    <ID>classname</ID>
                    <Function>ClassName()</Function>
                    <Default>ServiceClassName</Default>
                </Literal>
                <Literal>
                    <ID>OperationName</ID>
                    <Default>OperationName</Default>
                </Literal>
                <Literal>
                    <ID>Async</ID>
                    <Default>false</Default>
                </Literal>
            </Declarations>
            <Code Kind="method decl" Language="CSharp">
                <![CDATA[
        #region $OperationName$
        /// <summary>
        /// $OperationName$ is a Windows Communication Foundation operation contract.
        /// The operation definition is as follows:
        /// 
        /// Name:             $OperationName$
        /// Action:           $Namespace$$classname$.$OperationName$
        /// Reply Action:     $Namespace$$classname$.$OperationName$Reply
        /// Protection Level: $ProtectionLevel$
        /// Async Pattern:    $Async$
        /// One Way:          false
        /// Request Message:  $OperationName$RequestMessage
        /// Response Message: $OperationName$ResponseMessage
        /// </summary>
        /// <param name="request">The message representing the request</param>
        /// <returns>The message representing the response</returns>
        #region $OperationName$ definition
        [$sysOpContract$(
            Name = "$OperationName$",
            Action = "$Namespace$$classname$.$OperationName$",
            ReplyAction = "$Namespace$$classname$.$OperationName$Reply",
            ProtectionLevel = $PL$.$ProtectionLevel$,
            AsyncPattern = $Async$,
            IsOneWay = false)]
        $OperationName$ResponseMessage $OperationName$($OperationName$RequestMessage request);
        #endregion
        #endregion
]]>
            </Code>
        </Snippet>
    </CodeSnippet>
    <!-- wcf-op-contract-one-way -->
    <CodeSnippet Format="1.0.0">
        <Header>
            <Author>Stephen Horsfield</Author>
            <Description>This snippet creates a basic WCF operation contract outline</Description>
            <Keywords>
                <Keyword>WCF</Keyword>
                <Keyword>Operation</Keyword>
                <Keyword>Contract</Keyword>
            </Keywords>
            <Shortcut>wcf-op-contract-one-way</Shortcut>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
            <Title>wcf-op-contract-one-way</Title>
        </Header>
        <Snippet>
            <References>
                <Reference>
                    <Assembly>System.ServiceModel.dll</Assembly>
                </Reference>
                <Reference>
                    <Assembly>System.Runtime.Serialization.dll</Assembly>
                </Reference>
            </References>
            <Declarations>
                <Literal>
                    <ID>Namespace</ID>
                    <ToolTip>The namespace of the service</ToolTip>
                    <Default>urn:tempuri.org/services/</Default>
                </Literal>
                <Literal>
                    <ID>ProtectionLevel</ID>
                    <ToolTip>The minimum ProtectionLevel of the service</ToolTip>
                    <Default>None</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>PL</ID>
                    <Function>SimpleTypeName(global::System.Net.Security.ProtectionLevel)</Function>
                    <Default>global::System.Net.Security.ProtectionLevel</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>sysOpContract</ID>
                    <Function>SimpleTypeName(global::System.ServiceModel.OperationContractAttribute)</Function>
                </Literal>
                <Literal>
                    <ID>access</ID>
                    <Default>public</Default>
                </Literal>
                <Literal Editable="true">
                    <ID>classname</ID>
                    <Function>ClassName()</Function>
                    <Default>ServiceClassName</Default>
                </Literal>
                <Literal>
                    <ID>OperationName</ID>
                    <Default>OperationName</Default>
                </Literal>
                <Literal>
                    <ID>Async</ID>
                    <Default>false</Default>
                </Literal>
            </Declarations>
            <Code Kind="method decl" Language="CSharp">
                <![CDATA[
        #region $OperationName$
        /// <summary>
        /// $OperationName$ is a Windows Communication Foundation operation contract.
        /// The operation definition is as follows:
        /// 
        /// Name:             $OperationName$
        /// Action:           $Namespace$$classname$.$OperationName$
        /// Protection Level: $ProtectionLevel$
        /// Async Pattern:    false
        /// One Way:          true
        /// Request Message:  $OperationName$RequestMessage
        /// </summary>
        /// <param name="request">The message representing the request</param>
        #region $OperationName$ definition
        [$sysOpContract$(
            Name = "$OperationName$",
            Action = "$Namespace$$classname$.$OperationName$",
            ProtectionLevel = $PL$.$ProtectionLevel$,
            AsyncPattern = false,
            IsOneWay = true)]
        void $OperationName$($OperationName$RequestMessage request);
        #endregion
        #endregion
]]>
            </Code>
        </Snippet>
    </CodeSnippet>
    <!-- wcf-message-contract-pair -->
    <CodeSnippet Format="1.0.0">
        <Header>
            <Author>Stephen Horsfield</Author>
            <Description>This snippet creates a pair of WCF message contract outlines</Description>
            <Keywords>
                <Keyword>WCF</Keyword>
                <Keyword>Message</Keyword>
                <Keyword>Contract</Keyword>
            </Keywords>
            <Shortcut>wcf-message-contract-pair</Shortcut>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
            <Title>wcf-message-contract-pair</Title>
        </Header>
        <Snippet>
            <References>
                <Reference>
                    <Assembly>System.ServiceModel.dll</Assembly>
                </Reference>
                <Reference>
                    <Assembly>System.Runtime.Serialization.dll</Assembly>
                </Reference>
            </References>
            <Declarations>
                <Literal>
                    <ID>Namespace</ID>
                    <ToolTip>The namespace of the service</ToolTip>
                    <Default>urn:tempuri.org/services/</Default>
                </Literal>
                <Literal>
                    <ID>ProtectionLevel</ID>
                    <ToolTip>The minimum ProtectionLevel of the service</ToolTip>
                    <Default>None</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>PL</ID>
                    <Function>SimpleTypeName(global::System.Net.Security.ProtectionLevel)</Function>
                    <Default>global::System.Net.Security.ProtectionLevel</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>sysMsgContract</ID>
                    <Function>SimpleTypeName(global::System.ServiceModel.MessageContractAttribute)</Function>
                </Literal>
                <Literal Editable="false">
                    <ID>sysMsgBody</ID>
                    <Function>SimpleTypeName(global::System.ServiceModel.MessageBodyMemberAttribute)</Function>
                </Literal>
                <Literal Editable="false">
                    <ID>sysDataContract</ID>
                    <Function>SimpleTypeName(global::System.Runtime.Serialization.DataContractAttribute)</Function>
                </Literal>
                <Literal>
                    <ID>access</ID>
                    <Default>public</Default>
                </Literal>
                <Literal Editable="true">
                    <ID>classname</ID>
                    <Function>ClassName()</Function>
                    <Default>ServiceClassName</Default>
                </Literal>
                <Literal>
                    <ID>OperationName</ID>
                    <Default>OperationName</Default>
                </Literal>
                <Literal>
                    <ID>Async</ID>
                    <Default>false</Default>
                </Literal>
                <Literal>
                    <ID>ServiceClassName</ID>
                    <ToolTip>Name the service</ToolTip>
                    <Default>ServiceContract</Default>
                </Literal>
                <Literal>
                    <ID>NS</ID>
                    <ToolTip>The CLR namespace of the interface definition</ToolTip>
                    <Default>ServiceContracts</Default>
                </Literal>
            </Declarations>
            <Code Kind="file" Language="CSharp">
                <![CDATA[/*
  $NS$.$OperationName$RequestMessage
  $NS$.$OperationName$ResponseMessage
  
  This file contains a pair of Windows Communication Foundation Message Contract definitions for:
  
  Service:   $ServiceClassName$
  Operation: $OperationName$
  Namespace: $Namespace$$ServiceClassName$
*/
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Net.Security;
using System.Runtime.Serialization;
using System.Xml;

namespace $NS$ {

    #region $OperationName$RequestMessage
    /// <summary>
    /// $OperationName$RequestMessage is a Windows Communication Foundation messsage
    /// contract.  It is part of a Request-Response message pair.  The response
    /// message is $OperationName$ResponseMessage.
    /// 
    /// The body of the message is implemented by the $OperationName$RequestMessageBody
    /// type.
    /// 
    /// This message has the following definition:
    /// 
    /// Service:           $ServiceClassName$
    /// Operation:         $OperationName$
    /// Namespace:         $Namespace$$ServiceClassName$
    /// IsWrapped:         true
    /// Wrapper name:      $OperationName$RequestMessage
    /// Wrapper namespace: $Namespace$$ServiceClassName$
    /// Protection level:  $ProtectionLevel$
    /// </summary>
    [$sysMsgContract$(
        IsWrapped = true,
        ProtectionLevel = $PL$.$ProtectionLevel$,
        WrapperName = "$OperationName$RequestMessage",
        WrapperNamespace = "$Namespace$$ServiceClassName$")]
    $access$ class $OperationName$RequestMessage
    {
        [$sysMsgBody$(
            Name = "body",
            Namespace = "$Namespace$$ServiceClassName$/$OperationName$RequestMessage",
            Order = 0,
            ProtectionLevel = $PL$.$ProtectionLevel$)]
        public $OperationName$RequestMessageBody body;
    }
    #endregion

    #region $OperationName$ResponseMessage
    /// <summary>
    /// $OperationName$ResponseMessage is a Windows Communication Foundation messsage
    /// contract.  It is part of a Request-Response message pair.  The request
    /// message is $OperationName$RequestMessage.
    /// 
    /// The body of the message is implemented by the $OperationName$ResponseMessageBody
    /// type.
    /// 
    /// This message has the following definition:
    /// 
    /// Service:           $ServiceClassName$
    /// Operation:         $OperationName$
    /// Namespace:         $Namespace$$ServiceClassName$
    /// IsWrapped:         true
    /// Wrapper name:      $OperationName$ResponseMessage
    /// Wrapper namespace: $Namespace$$ServiceClassName$
    /// Protection level:  $ProtectionLevel$
    /// </summary>
    [$sysMsgContract$(
        IsWrapped = true,
        ProtectionLevel = $PL$.$ProtectionLevel$,
        WrapperName = "$OperationName$ResponseMessage",
        WrapperNamespace = "$Namespace$$ServiceClassName$")]
    $access$ class $OperationName$ResponseMessage
    {
        [$sysMsgBody$(
            Name = "body",
            Namespace = "$Namespace$$ServiceClassName$/$OperationName$ResponseMessage",
            Order = 0,
            ProtectionLevel = $PL$.$ProtectionLevel$)]
        public $OperationName$ResponseMessageBody body;
    }
    #endregion

    #region OperationNameRequestMessageBody
    /// <summary>
    /// $OperationName$RequestMessageBody is a Windows Communication Foundation data contract
    /// that provides an extensible message body structure for the $OperationName$RequestMessage
    /// message.
    /// 
    /// This class implements IExtensibleDataObject interface.
    /// 
    /// This data contract has the following definition:
    /// 
    /// Service:           $ServiceClassName$
    /// Operation:         $OperationName$
    /// Message:           $OperationName$RequestMessage
    /// Name:              $OperationName$RequestMessageBody
    /// Namespace:         $Namespace$$ServiceClassName$/$OperationName$RequestMessageBody
    /// </summary>
    [$sysDataContract$(
        Name = "$OperationName$RequestMessageBody",
        Namespace = "$Namespace$$ServiceClassName$/$OperationName$RequestMessageBody")]
    $access$ class $OperationName$RequestMessageBody : System.Runtime.Serialization.IExtensibleDataObject
    {

        #region IExtensibleDataObject Members
        private ExtensionDataObject _extensionData;
        public ExtensionDataObject  ExtensionData
        {
            get 
            { 
                return _extensionData;
            }
            set
            { 
                _extensionData = value;
            }
        }
        #endregion
    }
    #endregion

    #region OperationNameResponseMessageBody
    /// <summary>
    /// $OperationName$ResponseMessageBody is a Windows Communication Foundation data contract
    /// that provides an extensible message body structure for the $OperationName$ResponseMessage
    /// message.
    /// 
    /// This class implements IExtensibleDataObject interface.
    /// 
    /// This data contract has the following definition:
    /// 
    /// Service:           $ServiceClassName$
    /// Operation:         $OperationName$
    /// Message:           $OperationName$ResponseMessage
    /// Name:              $OperationName$ResponseMessageBody
    /// Namespace:         $Namespace$$ServiceClassName$/$OperationName$ResponseMessageBody
    /// </summary>
    [$sysDataContract$(
        Name = "$OperationName$ResponseMessageBody",
        Namespace = "$Namespace$$ServiceClassName$/$OperationName$ResponseMessageBody")]
    $access$ class $OperationName$ResponseMessageBody : System.Runtime.Serialization.IExtensibleDataObject
    {

        #region IExtensibleDataObject Members
        private ExtensionDataObject _extensionData;
        public ExtensionDataObject  ExtensionData
        {
            get 
            { 
                return _extensionData;
            }
            set
            { 
                _extensionData = value;
            }
        }
        #endregion
    }
    #endregion

}
]]>
            </Code>
        </Snippet>
    </CodeSnippet>
    <!-- wcf-message-contract-request-only -->
    <CodeSnippet Format="1.0.0">
        <Header>
            <Author>Stephen Horsfield</Author>
            <Description>This snippet creates a single WCF message contract for one-way messaging</Description>
            <Keywords>
                <Keyword>WCF</Keyword>
                <Keyword>Message</Keyword>
                <Keyword>Contract</Keyword>
            </Keywords>
            <Shortcut>wcf-message-contract-request-only</Shortcut>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
            <Title>wcf-message-contract-request-only</Title>
        </Header>
        <Snippet>
            <References>
                <Reference>
                    <Assembly>System.ServiceModel.dll</Assembly>
                </Reference>
                <Reference>
                    <Assembly>System.Runtime.Serialization.dll</Assembly>
                </Reference>
            </References>
            <Declarations>
                <Literal>
                    <ID>Namespace</ID>
                    <ToolTip>The namespace of the service</ToolTip>
                    <Default>urn:tempuri.org/services/</Default>
                </Literal>
                <Literal>
                    <ID>ProtectionLevel</ID>
                    <ToolTip>The minimum ProtectionLevel of the service</ToolTip>
                    <Default>None</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>PL</ID>
                    <Function>SimpleTypeName(global::System.Net.Security.ProtectionLevel)</Function>
                    <Default>global::System.Net.Security.ProtectionLevel</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>sysMsgContract</ID>
                    <Function>SimpleTypeName(global::System.ServiceModel.MessageContractAttribute)</Function>
                </Literal>
                <Literal Editable="false">
                    <ID>sysMsgBody</ID>
                    <Function>SimpleTypeName(global::System.ServiceModel.MessageBodyMemberAttribute)</Function>
                </Literal>
                <Literal Editable="false">
                    <ID>sysDataContract</ID>
                    <Function>SimpleTypeName(global::System.Runtime.Serialization.DataContractAttribute)</Function>
                </Literal>
                <Literal>
                    <ID>access</ID>
                    <Default>public</Default>
                </Literal>
                <Literal Editable="true">
                    <ID>classname</ID>
                    <Function>ClassName()</Function>
                    <Default>ServiceClassName</Default>
                </Literal>
                <Literal>
                    <ID>OperationName</ID>
                    <Default>OperationName</Default>
                </Literal>
                <Literal>
                    <ID>Async</ID>
                    <Default>false</Default>
                </Literal>
                <Literal>
                    <ID>ServiceClassName</ID>
                    <ToolTip>Name the service</ToolTip>
                    <Default>ServiceContract</Default>
                </Literal>
                <Literal>
                    <ID>NS</ID>
                    <ToolTip>The CLR namespace of the interface definition</ToolTip>
                    <Default>ServiceContracts</Default>
                </Literal>
            </Declarations>
            <Code Kind="file" Language="CSharp">
                <![CDATA[/*
  $NS$.$OperationName$RequestMessage
  $NS$.$OperationName$ResponseMessage
  
  This file contains a pair of Windows Communication Foundation Message Contract definitions for:
  
  Service:   $ServiceClassName$
  Operation: $OperationName$
  Namespace: $Namespace$$ServiceClassName$
*/
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Net.Security;
using System.Runtime.Serialization;
using System.Xml;

namespace $NS$ {

    #region $OperationName$RequestMessage
    /// <summary>
    /// $OperationName$RequestMessage is a Windows Communication Foundation messsage
    /// contract.  It is for a one-way message exchange and does not have a corresponding
    /// response message.
    /// 
    /// The body of the message is implemented by the $OperationName$RequestMessageBody
    /// type.
    /// 
    /// This message has the following definition:
    /// 
    /// Service:           $ServiceClassName$
    /// Operation:         $OperationName$
    /// Namespace:         $Namespace$$ServiceClassName$
    /// IsWrapped:         true
    /// Wrapper name:      $OperationName$RequestMessage
    /// Wrapper namespace: $Namespace$$ServiceClassName$
    /// Protection level:  $ProtectionLevel$
    /// </summary>
    [$sysMsgContract$(
        IsWrapped = true,
        ProtectionLevel = $PL$.$ProtectionLevel$,
        WrapperName = "$OperationName$RequestMessage",
        WrapperNamespace = "$Namespace$$ServiceClassName$")]
    $access$ class $OperationName$RequestMessage
    {
        [$sysMsgBody$(
            Name = "body",
            Namespace = "$Namespace$$ServiceClassName$/$OperationName$RequestMessage",
            Order = 0,
            ProtectionLevel = $PL$.$ProtectionLevel$)]
        public $OperationName$RequestMessageBody body;
    }
    #endregion

    #region OperationNameRequestMessageBody
    /// <summary>
    /// $OperationName$RequestMessageBody is a Windows Communication Foundation data contract
    /// that provides an extensible message body structure for the $OperationName$RequestMessage
    /// message.
    /// 
    /// This class implements IExtensibleDataObject interface.
    /// 
    /// This data contract has the following definition:
    /// 
    /// Service:           $ServiceClassName$
    /// Operation:         $OperationName$
    /// Message:           $OperationName$RequestMessage
    /// Name:              $OperationName$RequestMessageBody
    /// Namespace:         $Namespace$$ServiceClassName$/$OperationName$RequestMessageBody
    /// </summary>
    [$sysDataContract$(
        Name = "$OperationName$RequestMessageBody",
        Namespace = "$Namespace$$ServiceClassName$/$OperationName$RequestMessageBody")]
    $access$ class $OperationName$RequestMessageBody : System.Runtime.Serialization.IExtensibleDataObject
    {

        #region IExtensibleDataObject Members
        private ExtensionDataObject _extensionData;
        public ExtensionDataObject  ExtensionData
        {
            get 
            { 
                return _extensionData;
            }
            set
            { 
                _extensionData = value;
            }
        }
        #endregion
    }
    #endregion

}
]]>
            </Code>
        </Snippet>
    </CodeSnippet>
    <!-- wcf-data-member -->
    <CodeSnippet Format="1.0.0">
        <Header>
            <Author>Stephen Horsfield</Author>
            <Description>This snippet creates a basic WCF data contract member outline</Description>
            <Keywords>
                <Keyword>WCF</Keyword>
                <Keyword>Data</Keyword>
                <Keyword>Contract</Keyword>
            </Keywords>
            <Shortcut>wcf-data-member</Shortcut>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
            <Title>wcf-data-member</Title>
        </Header>
        <Snippet>
            <References>
                <Reference>
                    <Assembly>System.ServiceModel.dll</Assembly>
                </Reference>
                <Reference>
                    <Assembly>System.Runtime.Serialization.dll</Assembly>
                </Reference>
            </References>
            <Declarations>
                <Literal Editable="false">
                    <ID>sysDataMember</ID>
                    <Function>SimpleTypeName(global::System.Runtime.Serialization.DataMemberAttribute)</Function>
                </Literal>
                <Literal>
                    <ID>access</ID>
                    <Default>public</Default>
                </Literal>
                <Literal Editable="true">
                    <ID>PropertyName</ID>
                    <Default>PropertyName</Default>
                </Literal>
                <Literal>
                    <ID>type</ID>
                    <Default>System.String</Default>
                </Literal>
                <Literal>
                    <ID>order</ID>
                    <Default>0</Default>
                </Literal>
                <Literal>
                    <ID>required</ID>
                    <Default>true</Default>
                </Literal>
                <Literal>
                    <ID>emitDefault</ID>
                    <Default>true</Default>
                </Literal>
            </Declarations>
            <Code Kind="method decl" Language="CSharp">
                <![CDATA[
        #region $access$ $type$ $PropertyName$ (Name = "$PropertyName$", Order = $order$, IsRequired = $required$, EmitDefaultValue = $emitDefault$)
        /// <summary>
        /// $PropertyName$ forms part of the data contract.  It has the following options configured:
        /// 
        /// Name:             $PropertyName$
        /// Type:             $type$
        /// Order:            $order$
        /// Required:         $required$
        /// EmitDefaultValue: $emitDefault$
        /// </summary>
        [$sysDataMember$(
            EmitDefaultValue = $emitDefault$,
            IsRequired = $required$,
            Name = "$PropertyName$",
            Order = $order$)]
        $access$ $type$ $PropertyName$;
        #endregion
        
]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

Versions

Metadata

Tags:

SOA | Software Development

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar