Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Thursday, March 19, 2009

* REST in WCF and REST Starter kit

With the .NET Framework 3.5 release, WCF added support for building REST style services. REST support within WCF was enhanced with the release of .NET Framework 3.5 SP1 to add make REST development easier and to support the ADO.NET Entity Framework entities in WCF contracts.

REST Starter kit released independently of .NET framework improves development productivity by providing additional classes and Visual Studio templates for creating and consuming REST style WCF services.

Recently the preview 2 of REST starter kit was released on codeplex.

Here are important links for further reading:

Overview of REST in WCF and REST starter kit

Download REST starter kit Preview 2

Thursday, October 02, 2008

* What’s new in .NET 4.0 ?

Now that features of .NET 4.0 have started becoming officially public… I am also happy to start blogging about them.

Based on the available info.. here is the link containing the new features coming out in .NET framework 4.0.

What’s new in .net framework 4.0

I will be updating this link on regular basis .. so bookmark it.

Wednesday, September 19, 2007

* WCF : Hosting in Partial or Medium Trust ASP.NET environment

  • Read about ASP.NET Partial Trust environment.
  • Currently WCF provides very little support for partial trusted environment.
  • When hosting in medium trust environment - only basicHttpBinding is supported by default. If you want to use wsHttpBinding, security mode needs to be set as 'None' or 'Transport'. Default security mode for wsHttpBinding is 'Message'.
  • Partially trusted callers are currently not allowed to call WCF services.

Thursday, August 16, 2007

* WCF : Understanding Security

Previous Post <<-- WCF : Service Instances and Sessions

By now I have completed most of the mandatory features of WCF which any WCF developer should know except 'Security' which I will cover in this post. After this we will scope, design and develop our WCF real world application. If you have any ideas about real world application which we can use, pls let me know.

Security requirements from any distributed technology can be classified into one of the following :

  1. Authentication (client & service)
  2. Confidentiality
  3. Integrity
  4. Replay Attacks
  5. Authorization (Access control)
  6. Evidence based Security ( Auditing)

For 1, 2 & 3 WCF provides mainly three modes to ensure security apart from 'None'.

  • Transport : Transport protocol is responsible for it e.g. Https
  • Message : SOAP message security according to WS-Security standards
  • Mixed Mode : Transport Security is used for Integrity, Confidentiality and Server Authentication. Message security for client authentication.

Transport mode is recommended for homogenous environment like 'All Windows' environment as it is most performing and required least of coding.

Message is very flexible and can be used to implement security requirements in heterogeneous environment which is not based on standards.

Mixed Mode gives best of both the other modes. Is recommended for Web based scenarios.

Replay Attacks are taken care by Transport security if Transport or Mixed Mode are used. For Message Mode, WCF provides various settings which can be used as part of Custom Binding like 'DetectReplay' , 'MaxClockSkew', 'ReplayWindow'.

Authorization can be implemented using various mechanism provided by .NET framework and ASP.NET engine e.g. PrincipalPermissionAttribute, ASP.NET membership and role providers.

While WCF provides exhaustive Message logging and tracing infrastructure, the security audit can also be enabled using configuration by using ServiceSecurityAudit behavior.

Above was the overview of main security features available in WCF, we will try to cover most of them in our final application.

* WCF : Service Instances and Sessions

Previous Post <<-- WCF : Understanding Data Contracts (Deep Dive)

WCF allows developers to decide on how WCF should create instances of Service Object in response to client calls. It can be controlled by applying design time behavior attribute "System.ServiceModel.ServiceBehaviorAttribute.InstanceContextMode" over service implementation.

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
public class MathService : IMathService
{
    …
}

Following three instancing modes are available :

  1. PerCall : for each client call, a new service object is created.
  2. PerSession : If sessions are supported, a new object is created for each session and continues to service the client calls throughout the lifetime of session.
  3. Single : a single service object is created which handles all client requests from all clients throughout the lifetime of application.

The session related behavior of WCF service can also be controlled by design time behavior attribute "System.ServiceModel.ServiceContractAttribute.SessionMode". The values which can be set are : Allowed, NotAllowed and Required.

Sessions are initiated and terminated by calling client and there is no data store associated with sessions as in ASP.NET. Messages are processed in the order they are received.

If the instancing mode has been set as 'PerSession', only one Service object will be created for each session which will service the client throughout the lifetime of session.

Before getting more into sessions let me explain, What are Reliable Sessions ?

Reliable session makes sure that :

  • Each message gets delivered only once
  • Message are received by receiver in the same order as they have been sent.

When working with session aware communication there are two options available for developers to make sure that sessions created are reliable :

  • Use the transport binding which inherently provides reliable sessions like TCP.
  • Use WCF bindings which guarantee reliable sessions even over unreliable transport bindings like HTTP. The default system provided bindings which give an options of reliable sessions are :
    • WSHttpBinding
    • WSFederationHttpBinding
    • NetTCpBinding
    • WSDualHttpBinding

Here is a sample configuration which shows how to configure reliable session on WSHttpBinding

    <bindings>
<wsHttpBinding>
<binding name="BindingName">
<reliableSession enabled="true" ordered="true" />
</binding>
</wsHttpBinding>
</bindings>

 


Next Post -->> WCF : Understanding Security

 

* WCF : Understanding Data Contracts (Deep Dive)

Previous Post <<-- WCF Diagnostics : Message Logging

  • Data contract is the understanding between client and service about the structure of the data which needs to be transferred between client and service in as native/simplest/standard form as possible. This removes the dependency of sharing types between client and service. e.g. in case of wsHttpBinding the data contract is in form of data types as defined by W3 Standard to make it fully interoperable.
  • Only types which are marked by attribute DataContract or DataMember are serialized. Most of the native types are by default serialization enabled.
  • Member accessibility levels (internal, private, protected, or public) do not affect the data contract.
  • The DataMemberAttribute is ignored if it is applied to static members.
  • Data Contract and Data Members can be given a name other than the type name by 'name' property.
    [DataMember(Name = "Address")]
    public string MyAddress;

  • For client and service to be able to understand each others data successfully, the data contract on both the sides should be same. Here are few requirements for equivalence of data contracts :

    • Data contracts should have same name and namespace. They need to have same data members.
    • Data members should have same name and their Data Contracts should be equivalent.
    • All names and namespaces are case sensitive.
    • Data members should be in same order. Default order is alphabetical.

  • Order of Data Member can changed using 'Order' property.
        [DataMember(Order = 1)]
    public int B;
    [DataMember(Order = 2)]
    public int A;

  • If you plan to support more than one data contract using one type, you can use 'KnownType' attribute. Using this you can support the derived contracts also.
  • For creating forward-compatible data contract, the type should implement IExtensibleDataObject which has only one property ExtensionDataObject. This ensures that data doesn't get lost when moving between old and new contract with difference of data members.
  • Adding or Removing data fields from contracts generally don't break the communication unless the members have been made mandatory. When a type with an extra field is deserialized into a type with a missing field, the extra information is ignored. When a type with a missing field is deserialized into a type with an extra field, the extra field is left at its default value, usually zero or null.

 Next Post -->> WCF : Service Instances and Sessions

Monday, August 13, 2007

* WCF Diagnostics : Message Logging

Previous Post <<-- WCF Tool : Service Trace Viewer Tool (SvcTraceViewer.exe)

WCF provides sufficient, excellent and configurable out of box configurable message logging facility to monitor and troubleshoot incoming and outgoing messages. This is one of the major improvement over Remoting infrastructure.

  • Message Logging is OFF by default.
  • It provides various levels and options to configure extent of message logging.
  • Service Level : At this level the message is logged when it is about to leave or enter the code. Secure messages are logged decrypted at this level.
  • Transport Level : At this level messages are logged just before getting encoded or after getting decoded for transmission over wire. Even reliable messaging messages are logged.
  • Malformed Level : All the messages which WCF fails to process due to improper format gets logged.
  • Message Filters : Can be applied at Service and Transport. Only messages which match the filter are logged. Filters cannot be applied to Message body.
  • Enabling Message logging for a WCF service involves two modifications to WCF service config file.
  • Adding <diagnostics> section in <system.serviceModel> for setting various levels and options of message logging.
  • Adding <source name="System.ServiceModel.MessageLogging"> in <system.diagnostics> for setting up the listener and logging file.
  • Consider the post "WCF : Monitoring & Troubleshooting using Tracing" . Let's enable message logging also as part of this config file.
  • Add following to <system.serviceModel> section :
          <diagnostics>
    <messageLogging
    logEntireMessage="true"
    logMalformedMessages="true"
    logMessagesAtServiceLevel="true"
    logMessagesAtTransportLevel="true"
    maxMessagesToLog="3000"
    maxSizeOfMessageToLog="2000"/>
    </diagnostics>

  • Add another source to <system.diagnostics> section as following :
    <source name="System.ServiceModel.MessageLogging">
    <listeners>
    <add name="MessageLog"
    type="System.Diagnostics.XmlWriterTraceListener"
    initializeData="D:\Message.svclog" />
    </listeners>
    </source>

  • If you open the above trace file using Service Trace Viewer, You will see multiple following messages 'TransportSend', 'TransportReceive', 'ServiceLevelReceiveRequest' and 'ServiceLevelSendReply'  as we have enabled both service and transport level messages.
  • If the want to see the arguments passed by client and response returned by service, see the following message types : ServiceLevelReceiveRequest - System.ServiceModel.Security.SecurityVerifiedMessage and ServiceLevelSendReply - System.ServiceModel.Dispatcher.OperationFormatter+OperationFormatterMessage

 Next Post -->> WCF : Understanding Data Contracts (Deep Dive)

Friday, August 03, 2007

* WCF : Hosting WCF service in IIS

Previous Post <- WCF Tool : WCF IIS Registration Tool (ServiceModelReg.exe)

  • Pls start from the project created in following post : Developing a basic WCF client and service
  • Add a class which will be used to store two numbers.
        [DataContract]
    public class Numbers
    {
    private int firstNumber;
    private int secondNumber;
    [DataMember]
    public int FirstNumber
    {
    set
    {
    firstNumber = value;
    }
    get
    {
    return firstNumber;
    }
    }
    [DataMember]
    public int SecondNumber
    {
    set
    {
    secondNumber = value;
    }
    get
    {
    return secondNumber;
    }
    }
    }

  • Add another method to the contract which takes instance of Numbers and return the total of the two numbers stored in object.
            [OperationContract]
    int AddNum(Numbers numbers);

  • Create a Virtual Directory in IIS say with name as MathService.
  • Create a text file in this vd with name as MathService.svc
    <% @ServiceHost Service="MathUtility.MathService" %>

  • Create a bin folder in this directory. Add Service library to this folder.
  • Add web.config to vd where we will add our wcf service config details.
    <configuration>
    <!-- This Section is exclusive for WCF configuration for both service and client -->
    <system.serviceModel>
    <!-- This section is to declare services hosted using this cofig file -->
    <services>
    <!-- This section declares individual service. name=type name which implements service contract -->
    <!-- behaviorConfiguration = name of bahavior config which we will define later -->
    <service name="MathUtility.MathService" behaviorConfiguration="MathServiceBehavior">
    <!-- the actual address where service is exposed -->
    <endpoint address="" binding="wsHttpBinding" contract="MathUtility.IMath"></endpoint>
    <!-- The address where metadata is exposed and will be used by Svcutil.exe to generate client classes -->
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
    </service>
    </services>
    <behaviors>
    <serviceBehaviors>
    <!-- The behavior which we mentioned above in <service> section-->
    <behavior name="MathServiceBehavior">
    <!-- Exposing metadata on http. Not mandatory for fuctioning of service if client already has metadata-->
    <serviceMetadata httpGetEnabled="True"/>
    </behavior>
    </serviceBehaviors>
    </behaviors>
    </system.serviceModel>
    </configuration>

  • Note there is no <host> tag as we mentioned in self-hosted service because IIS with the virtual directory defines the base address of the service.
  • In this case our service will be hosted at following url : http://<My_Machine>/mathservice/mathservice.svc
  • Access the above url and you will see a default page generated with information on service.
  • You can use svcutil to generate the client code as explained in earlier post to build client and test your service.
  • The address which can be provided to svcutil can be one of following :

    • http://<My_Machine>/mathservice/mathservice.svc?wsdl


    • http://<My_Machine>/mathservice/mathservice.svc


    • http://<My_Machine>/mathservice/mathservice.svc/mex

  • My console app code which uses generated  client.
    using System;
    using System.Collections.Generic;
    using System.Text;
    using MathUtility;

    namespace ClientToIIS
    {
    class Program
    {
    static void Main(string[] args)
    {
    MathClient mathClient = new MathClient();
    Numbers number = new Numbers();
    number.FirstNumber = 1;
    number.SecondNumber = 2;
    Console.WriteLine(mathClient.AddNum(number));
    }
    }
    }

  • For simplicity you can trim the generated client side app.config to only following mandatory elements.
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <system.serviceModel>
    <client>
    <endpoint address="http://<My_Machine>/MathService/MathService.svc"
    binding="wsHttpBinding"
    contract="IMath" >
    </endpoint>
    </client>
    </system.serviceModel>
    </configuration>

Next Post ->> WCF : Diagnostics Features

 
 




* WCF Tool : WCF IIS Registration Tool (ServiceModelReg.exe)

Previous Post <<- WCF : Overview of Hosting in IIS

This tool is used to manage the registration of ServiceModel with IIS. ServiceModel is required for hosting WCF services in IIS.

Although if IIS is already present machine where .NET 3.0 is installed, the ServiceModel gets registered automatically but it case of issues this tool can be used for following :

  • Registration
  • Re-Registration
  • UnRegister
  • List all the components registered
  • Verification of registered components.

This tool can be found at following location : %windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation

If you have installed pre-release versions of WCF, you will have to do some manual changes in  machine.config. Pls chk MSDN for same.

Next Post -> WCF : Hosting WCF service in IIS

* WCF : Overview of Hosting in IIS

Previous Post <<-- WCF Tool : ServiceModel Metadata Utility Tool (Svcutil.exe)

  • WCF services hosted in IIS get all the benefits of IIS environment like scalability, recycling, etc.
  • Can be hosted on IIS 5.1, 6.0 and 7.0
  • 5.1 is recommended only for development while 6.0 and 7.0 can be used for production.
  • 6.0 supports only http but as IIS 7.0 uses Windows Activation Service (WAS) for protocol activation and communication, protocols other than http are also supported.
  • Before WCF services can be hosted in IIS, a WC HTTP activation component (ServiceModel) needs to be installed and registered in IIS.
  • You can verify the installation of this component using tool called ServiceModel Registration Tool.
  • WCF services can be hosted in same AppDomain as ASP.NET application in two modes : 1) Side-by-Side 2) ASP.NET Compatibility Mode
  • In 'Side-by-Side' ASP.NET and WCF share the AppDomain state & so static variables etc. But ASP.NET HTTP Runtime process only ASP.NET requests and doesn't participate in processing of WCF requests. HttpContext, HttpModules and ASP.NET Impersonation features are not available to WCF services. WCF Services can communicate on protocols other than HTTP on IIS 7.0.
  • In 'ASP.NET Compatibility Mode', WCF requests participate in HTTP request pipeline and thus can't communicate over other protocols other than HTTP.
  • WCF Services code can be deployed on IIS either in App_Code folder as source files or as compiled assembly in bin folder of Virtual Directory.

Next Post -> WCF Tool : WCF IIS Registration Tool (ServiceModelReg.exe)

Wednesday, July 25, 2007

* Getting Ready for WCF

Before we start getting into WCF from coming Monday, following environment needs to be ready :

Pls let me know if there are any queries regarding this.

Next Post ->> WCF : Windows Communication Foundation (WCF) : An Overview

Monday, July 23, 2007

* Celebrating Windows Communication Foundation

Dear Readers,

I will be blogging exclusively on Windows Communication Foundation from July 30th for 3 weeks till 20th August.

It will start with the most basic tutorials & concepts and move towards advanced one.

I am also going to cover some posts on how to migrate from Remoting to WCF for existing users.

So, Pls join me by giving your ideas and feedback on this great technology.

Next Post ->> Getting Ready for WCF

Tuesday, May 22, 2007

* Windows Communication Foundation (WCF) - A Primer - I

INTRODUCTION                                                                  

As the name explains :

"It is the technology platform on windows to enable applications so that they can communicate with each other in various formats, protocols and with various levels of coupling. It also enables windows based applications to expose/consume standard based interfaces across other platforms in form of web services."

Although it has been written from scratch it replaces various earlier .NET distributed computing technologies like remoting and consolidate them into one platform. It is interoperable with WSE 3.0, System.Messaging, .NET Enterprise Services, and ASMX Web services.

It uses schemas and contracts instead of classes & types to define and implement communication.

 

ARCHITECTURE                                                                   

WCF services expose endpoints that clients and services use to exchange messages.

Each endpoint consists of an address, a binding, and a contract.

Address : It specifies where service is located and format is network protocol specific e.g. http or tcp.

Binding : It specifies transport protocol, security requirements & message encoding to be used by client & service for communication.

Contract : It defines what the service can do. WCF service publish multiple types of contracts like service contract, message contract, data contract etc.

WCF has primarily three types of contracts :
service contract
This contract defines the name of the service, its namespace, and other global attributes. The contract is defined by creating an interface and applying the ServiceContractAttribute attribute to the interface.
operation contract
The operation contract defines the parameters and return type of an operation. When creating an interface that defines the service contract, you also define the service operation contracts by applying the OperationContractAttribute attribute to each method definition.
data contract
The data types used by a service must be described in metadata to enable others to interoperate with the service. The descriptions of the data types are known as the data contract, and the types may be used in any part of a message, for example as parameters or return types.

WCF is basically a message based architecture where clients and servers communicate using messages instead of remote invocation like DCOM.

Currently WCF supports three message patterns :

One way messaging : client sends a message to service without expecting a response back

Request Response : client sends a message and waits for reply

Duplex Messaging : client & service send message to each other without the synchronization as required in request – response.

 

HOSTING                                                                               

Following are the various options available today for hosting WCF service with the features provided by them :

1. Self Hosted : Console application, Easy to deploy, not recommended for production environments.

2. Windows Service : no IIS required, Robust environment, message-activation not supported, recommended for light weight/use services.

3. IIS 5.1, IIS 6.0 : all the health controlling/monitoring features of IIS available, support HTTP only, scalable.

4. Windows Activation Service (WAS) : available from Longhorn/Vista, no IIS required, health controlling/monitoring features available.

5. IIS 7.0 : all the WAS benefits available, recommended if asp.net content needs to be executed.

To summarize, if Operating System is Windows Server 2008 (Longhorn)/Vista, WAS is the most recommended host.

 

BINDINGS                                                                              

Bindings contain details which are required by an endpoint of WCF Service. The information contained in Bindings can be classified mainly into three categories :

1. Protocols : details of security mechanism, transaction context, reliable messaging requirements etc.

2. Encoding : details about message encoding like text or binary.

3. Transport : Transport protocol to use like http or binary.

The last two elements are mandatory parts of any binding.

WCF framework comes with some pre-configured binding which can be directly used in applications without mentioning the details about them.

Some of the bindings available are :

1. basicHttpBinding : HTTP protocol binding confirming to WS-I profile specification.

2. wsHttpBinding : confirming to WS-* protocol.

3. NetNamedPipeBinding : for connecting endpoints on same machine.

4. NetMsmqBinding : uses queued message connections.

5. NetTcpBinding : optimized binding for cross machine communication

Custom Binding can be created to handle more complex requirements.

The main features of any binding are :

1. Interoperability Type : kind of integration possible like WS, .NET, peer, MSMQ, etc.

2. Security : Level of security e.g. Transport, Message or Mixed.

3. Encoding : Type of encoding supported e.g. Text, Binary, MTOM.

 

SECURITY                                                                            

Securing Services involves four aspects mainly :

1. Authentication : Who the client is and whether it is allowed to communicate with service.

2. Confidentiality : Encrypting communication between client and service.

3. Integrity : To make sure that the communication is tamper proof.

4. Authorization : The access or execution rights of the client with respect to the service.

The various modes of security supported in WCF to implement above requirements are :

1. Transport Mode : The underlying transport protocol like http take care of all the above requirements by default.

2. Message Mode : In this mode all the data required to satisfy above requirements flow as part of message headers.

3. Hybrid Mode : In the mode Confidentiality & Integrity requirements are taken care by Transport mode while Authentication & Authorization are implemented using Message Mode. This mode is also called 'Transport with Message Credentials'.

There are two additional modes that are specific to two bindings : the 'transport-credentials only' mode found on the BasicHttpBinding and the 'both' mode found on the NetMsmqBinding.

 

SAMPLE CONTRACT DEFINITION                                          

 

 [ServiceContract()] public interface IBank { [OperationContract] Account Deposit(Account depAccount, int amount); [OperationContract] Account GetBalance(string accountNum); [OperationContract] Account WithDraw(Account wdAccount, int amount); }


 


 [DataContract] public class Account { string accountNumber; int balance; [DataMember] public string AccountNumber { get { return accountNumber; } set { accountNumber = value; } } [DataMember] public int Balance { get { return balance; } set { balance = value; } } }


 


SAMPLE CONTRACT IMPLEMENTATION                                





    public class BankService : IBank


    {


        public Account Deposit(Account depAccount,int depValue)


        {


            depAccount.Balance = depAccount.Balance + depValue;


            return depAccount;


        }


        public Account WithDraw(Account wdAccount, int wdValue)


        {


            wdAccount.Balance = wdAccount.Balance - wdValue;


            return wdAccount;


        }


        public Account GetBalance(string accountNum)


        {


            Account acnt = new Account();


            acnt.AccountNumber = accountNum;


            acnt.Balance = 12345;


            return acnt;


        }


    }





OTHER POSTS



Friday, February 02, 2007

* DinnerNow : Showcase of .NET Technologies

A demo application showcasing all the latest Microsoft Technologies has been released on codeplex.

Its called DinnerNow.net and simulates a vortal where customers can order food from local restaurants for delivery to their doorsteps.

The technologies it covers are :

  • IIS 7.0
  • Asp.NET AJAX
  • LINQ
  • Windows Communication Foundation
  • Windows Workflow Foundation
  • Windows Presentation Foundation
  • Windows PowerShell
  • .NET Compact Framework

Its an excellent demo which can be downloaded with source code...

will post more about it .. as i complete my setup.

Other Posts

Monday, January 22, 2007

* How to build Authorization Module for TCP Remoting channel

From .NET 2.0, framework includes the security infrastructure for TCP channel which can be enabled just by configuration.

The below entry enables security for tcp channel

<configuration>
    <system.runtime.remoting>
        <application>
            <service>
                <wellknown mode="SingleCall" type="VikasGoyal.ImplementationClass, Server" objectUri="server.rem" />
            </service>
            <channels>
                <channel ref="tcp" secure="true" port="8080" impersonate="true" />
            </channels>
        </application>
    </system.runtime.remoting>
</configuration>

Apart from providing authentication support, centralized authorization hook has also been included which can be used to implement authorization on all connections made on the tcp channel.

The property added is authorizationModule. The sample below shows the usage :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.runtime.remoting>
        <application>
            <service>
                <wellknown mode="SingleCall" type="VikasGoyal.ImplementationClass, Server" objectUri="server.rem" />
            </service>
            <channels>
                <channel ref="tcp" secure="true" port="8080" impersonate="true" authorizationModule="VikasGoyal.Server.AuthorizationModule, Server, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
            </channels>
        </application>
    </system.runtime.remoting>
</configuration>

AuthorizationModule should implement System.Runtime.Remoting.Channels.IAuthorizeRemotingConnection interface which provides methods where authorization checks and decisions can be taken based on the client's network address and user identity.

Below is the sample implementation :

class AuthorizationModule : IAuthorizeRemotingConnection
        {
            public bool IsConnectingEndPointAuthorized(System.Net.EndPoint endPoint)
            {
                  Console.WriteLine("Connecting IP: " + endPoint);
                  return true;
            }

            public bool IsConnectingIdentityAuthorized(IIdentity identity)
            {
                Console.WriteLine("Connecting identity: " + identity.Name);
                return true;
            }
        }

 

Related Links

Security : SSPI in .NET 2.0

 

Monday, November 27, 2006

* WCF : Hosting Services

Following are the various options available today for hosting WCF service with the features provided by them :

1. Self Hosted : Console application, Easy to deploy, not recommended for production environments.

2. Windows Service : no IIS required, Robust environment, message-activation not supported, recommended for light weight/use services.

3. IIS 5.1, IIS 6.0 : all the health controlling/monitoring features of IIS available, support HTTP only, scalable.

4. Windows Activation Service (WAS) : available from Longhorn/Vista, no IIS required, health controlling/monitoring features available.

5. IIS 7.0 : all the WAS benefits available, recommended if asp.net content needs to be executed.

To summarize, if the OS is Longhorn/Vista the WAS is the most recommended Host.

 

del.icio.us tags: , , ,

* WCF : Securing Services (Basics)

Securing Services involves four aspects mainly :

1. Authentication : Who the client is and whether it is allowed to communicate with service.

2. Confidentiality : Encrypting communication between client and service.

3. Integrity : To make sure that the communication is tamper proof.

4. Authorization : The access or execution rights of the client with respect to the service.

The various modes of security supported in WCF to implement above requirements are :

1. Transport Mode : The underlying transport protocol like http take care of all the above requirements by default.

2. Message Mode : In this mode all the data required to satisfy above requirements flow as part of message headers.

3. Hybrid Mode : In the mode Confidentiality & Integrity requirements are taken care by Transport mode while Authentication & Authorization are implemented using Message Mode. This mode is also called 'Transport with Message Credentials'.

 There are two additional modes that are specific to two bindings : the 'transport-credentials only' mode found on the BasicHttpBinding and the 'both' mode found on the NetMsmqBinding.

 

del.icio.us tags: , , ,

Thursday, November 23, 2006

* WCF : Metadata Endpoints

Metadata endpoints are like any other endpoints and are used by service providers to publish metadata of their services in a more standard way.

Metadata of a service can be retrieved either by using a WS-Transfer GET request or a HTTP/GET request using the ?wsdl query string.

In the below example adding <serviceMetadata> element in behaviour and adding endpoint to publish it will enable WS-Transfer GET request.

To enable HTTP/GET request httpGetEnabled should be set as true.

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="VikasGoyal.WCF.BankService" behaviorConfiguration="BankServiceBehaviors" >
<endpoint contract="VikasGoyal.WCF.IBank" binding="wsHttpBinding"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="BankServiceBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>


</system.serviceModel>
</configuration>
 


del.icio.us tags: , , ,
    

Technorati tags: , , ,


* WCF : Endpoints

All communication in WCF happens through endpoints.

Each endpoint contains following details :

1. Address of the endpoint. It uniquely identifies the endpoint.

2. Binding information for the client.

3. Contract that identifies the methods available.

Sample config file :

In the below config the endpoint has base address while the second end point has address as baseAddress/mex

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="VikasGoyal.WCF.BankService" behaviorConfiguration="BankServiceBehaviors" >
        <endpoint contract="VikasGoyal.WCF.IBank" binding="wsHttpBinding"/>
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="BankServiceBehaviors" >
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>


Tuesday, November 21, 2006

* WCF : Bindings

Bindings contain details which are required to an endpoint of WCF Service. The information contained in Bindings can be classified mainly into three categories :

1. Protocols : details of security mechanism, transaction context, reliable messaging requirements etc.

2. Encoding : details about message encoding like text or binary.

3. Transport : Transport protocol to use like http or binary.

The last two elements are mandatory parts of any binding.

WCF framework comes with some pre-configured binding which can be directly used in applications without mentioning the details about them.

Some of the bindings available are :

1. basicHttpBinding : HTTP protocol binding confirming to WS-I profile specification.

2. wsHttpBinding : confirming to WS-* protocol.

3. NetNamedPipeBinding : for connecting endpoints on same machine.

4. NetMsmqBinding : uses queued message connections.

5. NetTcpBinding : optimized binding for cross machine communication

Custom Binding can be created to handle more complex requirements.

The main features of any binding are :

1. Interoperability Type : kind of integration possible like WS, .NET, peer, MSMQ, etc.

2. Security : Level of security e.g. Transport, Message or Mixed.

3. Encoding : Type of encoding supported e.g. Text, Binary, MTOM.

 

del.icio.us tags: , ,

 

Technorati tags: , ,