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

WCF 101 PowerPoint PPT Presentation


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

WCF 101. Barry Dorrans http://idunno.org. About the Speaker (the ego slide). MVP – Visual Tools, Security [email protected] 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

WCF 101

Barry Dorrans

http://idunno.org


About the speaker the ego slide

About the Speaker(the ego slide)

MVP – Visual Tools, Security

[email protected]


Agenda what is wcf the abcs of wcf defining a contract hosting the service handling errors logging

Agenda

What is WCF?

The ABCs of WCF

Defining a contract

Hosting the service

Handling Errors

Logging


What is wcf

What is WCF?

Indigo

Replaces Web Services, WSE & Remoting

Interoperability


The abcs of wcf

The ABCs of WCF

Address

Binding

Contract


Service model

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

Address

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

http://localhost:8080/Account/

net.tcp://localhost:8080/Account


Binding

Binding

How you communicate with a service

A service may have multiple bindings

Defines the shape; security etc.


Contract

Contract

The external interface

Contracts for service, data and message


The abcs

The ABCs

Address = WHERE

Binding = HOW

Contract = WHAT


Service contracts

Service Contracts

[ServiceContract()]

public interface IMyService

{

[OperationContract]

string MyOperation1(string myValue);

[OperationContract]

string MyOperation2(MyDataContract value);

}


Data contracts

Data Contracts

[DataContract]

public class MyDataContract

{

string _stuff;

[DataMember]

public string Stuff

{

get { return _stuff; }

set { stuff = value; }

}

}


Creating our first wcf service

Creating our first WCF service


So what have we learned

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?


Why data contracts1

Why data contracts?

Message body or Message Header

Control over the order of members

Required versus optional parameters


Version tolerance

Version Tolerance


So what have we learned1

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

Hosting the service


So what have we learned2

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

Hosting in a program

Create a new ServiceHost and Open

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

{

host.Open();

.....

}


Hosting in iis

Hosting in IIS

Add a .svc file

<[email protected] Service="Namespace.ServiceType" %>

<[email protected] Name="AssemblyName" %>


Replacing asmx

Replacing ASMX

Double Decorate Contracts

Watch the action & message names

Remap ASMX to WCF

Only use basicHttpBinding


Gotcha registering addresses

Gotcha! Registering addresses

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


Getting service information

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

Exceptions and errors.


So what have we learned3

So what have we learned?

Raw exceptions are not helpful

Inner exceptions are still not good

Contracted faults are the way to go


Logging

Logging


Questions

Questions?


  • Login