Monday, September 20, 2010

Fundamentals of Creating a WCF Client (WCF Part 6)

 


Fundamentals of Creating a WCF Client: Like almost all other distributed technologies, clients use proxies to access WCF services.

    Proxies can be created in one of two ways:

  1. at design time by using the svcutil.exe command line tool
  2. dynamically at runtime by using a ChannelFactory.

A ChannelFactory provides a flexible way to create proxies at runtime, by creating a factory from the address, binding details, and contract details, and then calling CreateChannel on the factory.


Creating a Client by Using a Channel Factory:

 

[C#]
ChannelFactorycf = new ChannelFactory(new EndpointAddress("http://localhost/MyService/EndPoint1"),new BasicHttpBinding());
IMyChannel ch1=cf.CreateChannel();

 

To send messages you must open the channel. and after finishing you have to Close the channel.

The ChannelFactory class has a number of methods and properties that enable you to access features of the underlying channel. e.g the Credentials property:

 

[C#]
proxy.ChannelFactory.Credentials.UserNamePassword.UserName = "Mohamed Adel Mahmoud";
proxy.ChannelFactory.Credentials.UserNamePassword.Password = “P@$$w0rd”;

 

 
  For More Info Please Visit: WCF Resources Page  

Sunday, September 19, 2010

WCF Hosting Options: (WCF Part 5)

 


Options for Hosting a WCF Service:

  1. Internet Information Server (IIS): WCF services can be hosted within Internet Information Services, which provides a number of advantages if the service uses HTTP as its transport protocol.

  2. Windows Activation Service: is the new process activation mechanism that is a feature of IIS 7.0. IIS 7.0 is a part of Microsoft Windows Vista and the newly released Microsoft Windows Server 2008.

  3. Self Hostd:WCF services can be hosted inside any .NET managed application, such as console applications and Windows Forms or Windows Presentation Foundation (WPF) graphical applications.

     

    [C#]
    ServiceHost myHost = new ServiceHost(typeof(MyService), baseAddress);
    myHost.Open(); //to start the service

     


  4. Managed Windows Service:A WCF service can be registered as a Windows Service, so that it is under control of the Windows Service Control Manager (SCM).

    This is suitable for long-running WCF services that are hosted outside of IIS in a secure environment and are not message- activated.

    To host a WCF service in this way, the application must be written as a Managed Windows Service by inheriting from System.ServiceProcess.ServiceBase

    It must also implement a WCF service contract interface and then create and open a ServiceHost to manage the WCF service.

 
  For More Info Please Visit: WCF Resources Page  

WCF Integration with MSMQ and COM+: (WCF Part 4)

 


WCF can act as the client or server to existing MSMQ applications. Using the MSMQ integration channel, WCF clients and services can exchange classic MSMQ messages with MSMQ applications.

Existing component-based application logic hosted in COM+ can be exposed as Web services. Each exposed COM class will be represented by a service, the contract for which is derived directly from the component's interface definition. The COM+ Service Model Configuration tool (ComSvcConfig.exe) is used to create Web services to represent COM interfaces.

 
  For More Info Please Visit: WCF Resources Page  

WCF Features (WCF Part 3)

 


WCF has many features like :

  1. WCF provides one model for writing distributed applications not as many models like before (COM+, MSMQ, etc)
  2. WCF Reduced the code
  3. WCF provides a comprehensive set of logging and tracing features

WCF Message Exchange Patterns:

WCF supports three message exchange patterns:

  1. In one-way messaging, also known as simplex messaging: a client sends a message to a service without expecting a response.

  2. In request-response messaging: a client sends a message to a service, and waits for a reply.

  3. In duplex messaging, the client and service communicate freely with each other without the synchronization that request- response messaging requires. Duplex messaging is used to implement asynchronous communication.

 
  For More Info Please Visit: WCF Resources Page  

Tools Provided by WCF. (WCF Part 2)

 


WCF provides a number of tools that make it easier to create, deploy, and administer WCF applications:

  1. COM+ Service Model Configuration Tool (ComSvcConfig.exe):provides a representation of the service contracts and bindings for WCF Web services that is both strongly typed and COM-visible, and enables developers of COM+ applications to expose one or more interfaces on a COM+ component as Web services.
  2. Configuration Editor (SvcConfigEditor.exe):Enables administrators and developers to create and modify configuration settings for WCF services by using a GUI.
  3. Find Private Key Tool (FindPrivateKey.exe):Retrieves a private key from a key store.
  4. ServiceModel Metadata Utility (svcutil.exe):Generates service model code from metadata, and metadata from service model code. Most often used to generate client-side proxies to WCF services.
  5. ServiceModel Registration Tool (ServiceModelReg.exe):Manages the registration of the WCF ServiceModel with Internet Information Services on a single computer. It can be used to register, unregister, and re- register WCF.
  6. TraceViewer Tool (SvcTraceViewer.exe):Enables developers and administrators to view, group, and filter trace messages that relate to WCF services.
  7. WS-AtomicTransaction Configuration Utility (wsatConfig.exe):Configures WS- AtomicTransaction support settings, such as ports, certificates, and accounts.
 
  For More Info Please Visit: WCF Resources Page  

Introduction to Windows Communication Foundation (WCF)

 


The Microsoft .Net FrameWork 3.5 consists of the .NET Framework version 2.0 components as well as 4 developer-focused innovative technologies:

  1. Windows Presentation Foundation (WPF)
  2. Windows Communication Foundation (WCF)
  3. Windows Workflow Foundation (WF)
  4. Windows CardSpace (CardSpace).

WCF services expose endpoints that clients and services use to exchange messages. Each endpoint consists of an 1- address, 2-a binding, and 3- a contract.

  1. The address identifies where the service is located on the network.
  2. The binding defines how the client needs to communicate with the service.(Security wise)
  3. The contract defines what the service can do.

 
  For More Info Please Visit: WCF Resources Page  

Search This Blog