Wcf 101
Sponsored Links
This presentation is the property of its rightful owner.
1 / 29

WCF 101 PowerPoint PPT Presentation


  • 131 Views
  • Uploaded on
  • Presentation posted in: General

WCF 101. Barry Dorrans http://idunno.org. About the Speaker (the ego slide). MVP – Visual Tools, Security barryd@idunno.org. Agenda What is WCF? The ABCs of WCF Defining a contract Hosting the service Handling Errors Logging. What is WCF?. Indigo

Download Presentation

WCF 101

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


WCF 101

Barry Dorrans

http://idunno.org


About the Speaker(the ego slide)

MVP – Visual Tools, Security

barryd@idunno.org


Agenda

What is WCF?

The ABCs of WCF

Defining a contract

Hosting the service

Handling Errors

Logging


What is WCF?

Indigo

Replaces Web Services, WSE & Remoting

Interoperability


The ABCs of WCF

Address

Binding

Contract


Client

Server

Messaging Layer

Endpoint

Service Model

Address

Binding

Channel

Behaviour

Behaviour

Contract

Binding

Binding

Channel

Behaviour

Behaviour

Factory

Listener

Channel

Address

Address

Channel

*


Address

scheme:// <machineName>[:port]/path

http://localhost:8080/Account/

net.tcp://localhost:8080/Account


Binding

How you communicate with a service

A service may have multiple bindings

Defines the shape; security etc.


Contract

The external interface

Contracts for service, data and message


The ABCs

Address = WHERE

Binding = HOW

Contract = WHAT


Service Contracts

[ServiceContract()]

public interface IMyService

{

[OperationContract]

string MyOperation1(string myValue);

[OperationContract]

string MyOperation2(MyDataContract value);

}


Data Contracts

[DataContract]

public class MyDataContract

{

string _stuff;

[DataMember]

public string Stuff

{

get { return _stuff; }

set { stuff = value; }

}

}


Creating our first WCF service


So what have we learned?

VS2008 gives us a test harness

Service behaviour in config

Barry can’t type under pressure.


Why data contracts?


Why data contracts?

Message body or Message Header

Control over the order of members

Required versus optional parameters


Version Tolerance


So what have we learned?

We need data contracts

Why? – Version Tolerance WCF exposes nothing by default

This is the opposite of XML Serialization


Hosting the service


So what have we learned?

We can host in IIS or a .net program

So we can use WCF for inter-process or inter-program communication


Hosting in a program

Create a new ServiceHost and Open

using (ServiceHost host = new ServiceHost(typeof(MyService)))

{

host.Open();

.....

}


Hosting in IIS

Add a .svc file

<%@ServiceHost Service="Namespace.ServiceType" %>

<%@Assembly Name="AssemblyName" %>


Replacing ASMX

Double Decorate Contracts

Watch the action & message names

Remap ASMX to WCF

Only use basicHttpBinding


Gotcha! Registering addresses

netsh http add urlaclurl=http://+:8080/echoService user=BUILTIN\Users


Getting service information

foreach (ServiceEndpoint endpoint in myServiceHost.Description.Endpoints)

{

Console.WriteLine("Endpoint - address: {0}", endpoint.Address);

Console.WriteLine("- binding name:\t\t{0}", endpoint.Binding.Name);

Console.WriteLine("- contract name:\t\t{0}", endpoint.Contract.Name);

}


Exceptions and errors.


So what have we learned?

Raw exceptions are not helpful

Inner exceptions are still not good

Contracted faults are the way to go


Logging


Questions?


  • Login