SlideShare a Scribd company logo
1 of 33
Top 10 Tricks & Tips for WCF

                 Barry Dorrans
             http://idunno.org
About the Speaker
   (the ego slide)

 MVP – Visual Tools, Security
        barryd@idunno.org
Agenda
     1) The test harnesses
        2) Don’t use Using
       3) It’s all your fault
    4) Migrating an ASMX
    5) Message Inspectors
6) Custom Authentication
            7) Port sharing
               8) Callbacks
                 9) Logging
      10) RESTful services
What is WCF?

                       Indigo
Replaces Web Services, WSE &
                   Remoting
             Interoperability
The ABCs of WCF

             Address
              Binding
             Contract
Service Model
     Client                                                               Server
                                 Messaging Layer
                                                     Endpoint
                                               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; }
    }
}
1 – The test harnesses
2 – Don’t use Using
Disposing the right way
Service1Client proxy = null;
try
{
    proxy = new Service1Client(....);
}
catch (...)
finally
{
    if (proxy != null)
    {
        try
        {
            if (proxy.State == CommunicationState.Opened)
                proxy.Close();
            else if (proxy.State == CommunicationState.Faulted)
                proxy.Abort();
        }
        catch (CommunicationException)
        {
            proxy.Abort();
        }
        catch (TimeoutException)
        {
            proxy.Abort();
        }
    }
}
3 - It’s all your fault
Faults the right way
In Contract Code

[ServiceContract]
public interface IService1
{
    [OperationContract]
    [FaultContract(typeof(NegativeNumberFault))]
    string GetDataWithFault(int value);
}
[DataContract]
public class NegativeNumberFault
{
}

In Service Code
throw new FaultException<NegativeNumberFault>(
     new NegativeNumberFault(),
     new FaultReason(quot;value was negativequot;));

In Client Code
try
{
      ....
}
catch (FaultException<NegativeNumberFault>)
{
      ....
}
4 – Migrating an ASMX
Migrating an ASMX
1. Change the protocol binding to
   basicHttpBinding
2. Match your namespaces
   [ServiceContract(Namespace=quot;http:/tempuri.org/quot;)]

3. Match your actions
   [OperationContract(Action = quot;http://tempuri.org/HelloWorldquot;)]

4. Match your message names (if you use them)
   [OperationContract(Action = quot;http://tempuri.org/HelloWorldquot;,
     Name = quot;MyMessageNamequot;)]

5. Change the serializer to use XmlSerializer
   [XmlSerializerAttribute]
   public class MyService
Migrating an ASMX
6. Make WCF answer ASMX
  <buildProviders>
    <remove extension=quot;.asmxquot;/>
    <add extension=quot;.asmxquot;
  type=quot;System.ServiceModel.Activation.ServiceBuildProvider,
  System.ServiceModel, Version=3.0.0.0, Culture=neutral,
  PublicKeyToken=b77a5c561934e089quot;/>
  </buildProviders>
5 – Message Inspectors
Message Inspectors
1. Can be client or server side
2. Messages can be modified – but you must copy
   the message then replace it.
3. Apply the custom behaviour via config or via
   an attribute.
6 – Custom Authentication
Custom Authentication
1. Reference System.IdentityModel and
   System.IdentityModel.Selectors
2. Implement a UsernamePasswordValidator
3. Plug it in via config
7 – Port Sharing
Port Sharing
1. Vista / Windows 2008 –
   netsh http add urlacl
       url=http://+:port/url/
       user=Everyone
2. XP / Windows 2003 (Support Tools)–
   httpcfg set urlacl
     /u http://*:80/url/
     /a D:(A;;GX;;;NS)
3. XP does not port share with IIS.
8 – Callbacks
Callbacks
1. Publish / Subscribe model works best
2. Declare a callback interface
  interface IMessageCallback
  {
     [OperationContract(IsOneWay = true)]
     void OnMessageAdded(string message, DateTime timestamp);
  }


3. Add the callback to the service contract.
   [ServiceContract(CallbackContract = typeof(IMessageCallback))]

4. Implement callback interface on client.
9 - Logging
10 – RESTful services
RESTful services
1. Reference System.ServiceModel.Web
2. Use WebHttpBinding and WebHttpBehavior
3. Decorate contract with WebGet or WebInvoke
   [OperationContract]
   [WebInvoke(Method = quot;POSTquot;, UriTemplate = quot;quot;)]
   void AddMessage(Message message);
   [OperationContract]
   [WebInvoke(Method = quot;DELETEquot;, UriTemplate = quot;{id}quot;)]
   void DeleteMessage(string id);
   [OperationContract]
   [WebGet(UriTemplate = quot;{id}quot;)]
   Message GetMessage(string id);
   [OperationContract]
   [WebGet(UriTemplate = quot;quot;)]
   List<Message> GetMessages();
RESTful services
4. Avoid the hassle and use the REST starter kit

   http://msdn.microsoft.com/en-us/netframework/wcf/rest
Questions?

More Related Content

What's hot

WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)ipower softwares
 
Interoperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) OverviewInteroperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) OverviewJorgen Thelin
 
WCF tutorial
WCF tutorialWCF tutorial
WCF tutorialAbhi Arya
 
Introduction to WCF
Introduction to WCFIntroduction to WCF
Introduction to WCFybbest
 
Beginning with wcf service
Beginning with wcf serviceBeginning with wcf service
Beginning with wcf serviceBinu Bhasuran
 
introduction to Windows Comunication Foundation
introduction to Windows Comunication Foundationintroduction to Windows Comunication Foundation
introduction to Windows Comunication Foundationredaxe12
 
Windows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) ServiceWindows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) ServiceSj Lim
 
1. WCF Services - Exam 70-487
1. WCF Services - Exam 70-4871. WCF Services - Exam 70-487
1. WCF Services - Exam 70-487Bat Programmer
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIKevin Hazzard
 
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUIAdvancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUIAdvancio
 
Session 1: The SOAP Story
Session 1: The SOAP StorySession 1: The SOAP Story
Session 1: The SOAP Storyukdpe
 
Web services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsWeb services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsPeter Gfader
 
Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Peter R. Egli
 
Introduction to SOAP/WSDL Web Services and RESTful Web Services
Introduction to SOAP/WSDL Web Services and RESTful Web ServicesIntroduction to SOAP/WSDL Web Services and RESTful Web Services
Introduction to SOAP/WSDL Web Services and RESTful Web Servicesecosio GmbH
 

What's hot (20)

WCF Introduction
WCF IntroductionWCF Introduction
WCF Introduction
 
WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)
 
Wcf
WcfWcf
Wcf
 
WCF
WCFWCF
WCF
 
Interoperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) OverviewInteroperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) Overview
 
WCF And ASMX Web Services
WCF And ASMX Web ServicesWCF And ASMX Web Services
WCF And ASMX Web Services
 
Windows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Best PracticesWindows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Best Practices
 
WCF tutorial
WCF tutorialWCF tutorial
WCF tutorial
 
Introduction to WCF
Introduction to WCFIntroduction to WCF
Introduction to WCF
 
Beginning with wcf service
Beginning with wcf serviceBeginning with wcf service
Beginning with wcf service
 
introduction to Windows Comunication Foundation
introduction to Windows Comunication Foundationintroduction to Windows Comunication Foundation
introduction to Windows Comunication Foundation
 
WCF
WCFWCF
WCF
 
Windows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) ServiceWindows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) Service
 
1. WCF Services - Exam 70-487
1. WCF Services - Exam 70-4871. WCF Services - Exam 70-487
1. WCF Services - Exam 70-487
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
 
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUIAdvancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
 
Session 1: The SOAP Story
Session 1: The SOAP StorySession 1: The SOAP Story
Session 1: The SOAP Story
 
Web services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsWeb services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows Forms
 
Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)
 
Introduction to SOAP/WSDL Web Services and RESTful Web Services
Introduction to SOAP/WSDL Web Services and RESTful Web ServicesIntroduction to SOAP/WSDL Web Services and RESTful Web Services
Introduction to SOAP/WSDL Web Services and RESTful Web Services
 

Viewers also liked

NoSQL Nedir MongoDB ile .NET Kardeşliği
NoSQL Nedir MongoDB ile .NET KardeşliğiNoSQL Nedir MongoDB ile .NET Kardeşliği
NoSQL Nedir MongoDB ile .NET Kardeşliğiİbrahim ATAY
 
GOOGLE: Designs, Lessons and Advice from Building Large Distributed Systems
GOOGLE: Designs, Lessons and Advice from Building Large   Distributed Systems GOOGLE: Designs, Lessons and Advice from Building Large   Distributed Systems
GOOGLE: Designs, Lessons and Advice from Building Large Distributed Systems xlight
 
Project Management with SharePoint 2010
Project Management with SharePoint 2010Project Management with SharePoint 2010
Project Management with SharePoint 2010Greg Kiefer
 
C# Advanced L08-Networking+WCF
C# Advanced L08-Networking+WCFC# Advanced L08-Networking+WCF
C# Advanced L08-Networking+WCFMohammad Shaker
 
ASP.Net MVC ile Web Uygulamaları -8(NHibernate)
ASP.Net MVC ile Web Uygulamaları -8(NHibernate)ASP.Net MVC ile Web Uygulamaları -8(NHibernate)
ASP.Net MVC ile Web Uygulamaları -8(NHibernate)İbrahim ATAY
 
Building single page applications
Building single page applicationsBuilding single page applications
Building single page applicationsSC5.io
 
Advanced WCF Workshop
Advanced WCF WorkshopAdvanced WCF Workshop
Advanced WCF WorkshopIdo Flatow
 
Web API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonAdnan Masood
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To MvcVolkan Uzun
 
Аналитические решения в телекомах. Презентация с киевского мероприятия 27.09.12
Аналитические решения в телекомах. Презентация с киевского мероприятия 27.09.12Аналитические решения в телекомах. Презентация с киевского мероприятия 27.09.12
Аналитические решения в телекомах. Презентация с киевского мероприятия 27.09.12Alexey Kononenko
 
отчёт Антикризис
отчёт Антикризисотчёт Антикризис
отчёт АнтикризисunDrei
 
Capodian Investment Management
Capodian Investment ManagementCapodian Investment Management
Capodian Investment ManagementAnthonySchnur
 

Viewers also liked (20)

NoSQL Nedir MongoDB ile .NET Kardeşliği
NoSQL Nedir MongoDB ile .NET KardeşliğiNoSQL Nedir MongoDB ile .NET Kardeşliği
NoSQL Nedir MongoDB ile .NET Kardeşliği
 
Nosql ve mongoDB
Nosql ve mongoDBNosql ve mongoDB
Nosql ve mongoDB
 
GOOGLE: Designs, Lessons and Advice from Building Large Distributed Systems
GOOGLE: Designs, Lessons and Advice from Building Large   Distributed Systems GOOGLE: Designs, Lessons and Advice from Building Large   Distributed Systems
GOOGLE: Designs, Lessons and Advice from Building Large Distributed Systems
 
Making WCF Simple
Making WCF SimpleMaking WCF Simple
Making WCF Simple
 
Project Management with SharePoint 2010
Project Management with SharePoint 2010Project Management with SharePoint 2010
Project Management with SharePoint 2010
 
C# Advanced L08-Networking+WCF
C# Advanced L08-Networking+WCFC# Advanced L08-Networking+WCF
C# Advanced L08-Networking+WCF
 
ASP.Net MVC ile Web Uygulamaları -8(NHibernate)
ASP.Net MVC ile Web Uygulamaları -8(NHibernate)ASP.Net MVC ile Web Uygulamaları -8(NHibernate)
ASP.Net MVC ile Web Uygulamaları -8(NHibernate)
 
Web Service Security
Web Service SecurityWeb Service Security
Web Service Security
 
Burpsuite yara
Burpsuite yaraBurpsuite yara
Burpsuite yara
 
Building single page applications
Building single page applicationsBuilding single page applications
Building single page applications
 
Pentesting RESTful WebServices v1.0
Pentesting RESTful WebServices v1.0Pentesting RESTful WebServices v1.0
Pentesting RESTful WebServices v1.0
 
Pentesting ReST API
Pentesting ReST APIPentesting ReST API
Pentesting ReST API
 
Advanced WCF Workshop
Advanced WCF WorkshopAdvanced WCF Workshop
Advanced WCF Workshop
 
Web API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural Comparison
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
 
Аналитические решения в телекомах. Презентация с киевского мероприятия 27.09.12
Аналитические решения в телекомах. Презентация с киевского мероприятия 27.09.12Аналитические решения в телекомах. Презентация с киевского мероприятия 27.09.12
Аналитические решения в телекомах. Презентация с киевского мероприятия 27.09.12
 
отчёт Антикризис
отчёт Антикризисотчёт Антикризис
отчёт Антикризис
 
Capodian Investment Management
Capodian Investment ManagementCapodian Investment Management
Capodian Investment Management
 
Eerlijk Duurt Het Langst
Eerlijk Duurt Het LangstEerlijk Duurt Het Langst
Eerlijk Duurt Het Langst
 
Translation Engine
Translation EngineTranslation Engine
Translation Engine
 

Similar to 10 Tricks and Tips for WCF

A presentation on WCF & REST
A presentation on WCF & RESTA presentation on WCF & REST
A presentation on WCF & RESTSanthu Rao
 
Web services in java
Web services in javaWeb services in java
Web services in javamaabujji
 
WINDOWS COMMUNICATION FOUNDATION
WINDOWS COMMUNICATION FOUNDATIONWINDOWS COMMUNICATION FOUNDATION
WINDOWS COMMUNICATION FOUNDATIONDeepika Chaudhary
 
Web services
Web servicesWeb services
Web servicesaspnet123
 
WCF and WF in Framework 3.5
WCF and WF in Framework 3.5WCF and WF in Framework 3.5
WCF and WF in Framework 3.5ukdpe
 
Jasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-casJasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-casellentuck
 
Consul: Service Mesh for Microservices
Consul: Service Mesh for MicroservicesConsul: Service Mesh for Microservices
Consul: Service Mesh for MicroservicesArmonDadgar
 
What is new in WCF 4.0?
What is new in WCF 4.0?What is new in WCF 4.0?
What is new in WCF 4.0?Bala Subra
 
Understanding Web Services by software outsourcing company india
Understanding Web Services by software outsourcing company indiaUnderstanding Web Services by software outsourcing company india
Understanding Web Services by software outsourcing company indiaJignesh Aakoliya
 
Top wcf interview questions
Top wcf interview questionsTop wcf interview questions
Top wcf interview questionstongdang
 
Wcf best practice
Wcf best practiceWcf best practice
Wcf best practiceYu GUAN
 
Decompose That WAR! Architecting for Adaptability, Scalability, and Deployabi...
Decompose That WAR! Architecting for Adaptability, Scalability, and Deployabi...Decompose That WAR! Architecting for Adaptability, Scalability, and Deployabi...
Decompose That WAR! Architecting for Adaptability, Scalability, and Deployabi...Chris Richardson
 
Dot Net Training Wcf Dot Net35
Dot Net Training Wcf Dot Net35Dot Net Training Wcf Dot Net35
Dot Net Training Wcf Dot Net35Subodh Pushpak
 
Complete Architecture and Development Guide To Windows Communication Foundati...
Complete Architecture and Development Guide To Windows Communication Foundati...Complete Architecture and Development Guide To Windows Communication Foundati...
Complete Architecture and Development Guide To Windows Communication Foundati...Abdul Khan
 

Similar to 10 Tricks and Tips for WCF (20)

WCF 4 Overview
WCF 4 OverviewWCF 4 Overview
WCF 4 Overview
 
Wcf
Wcf Wcf
Wcf
 
Wcf faq
Wcf faqWcf faq
Wcf faq
 
A presentation on WCF & REST
A presentation on WCF & RESTA presentation on WCF & REST
A presentation on WCF & REST
 
Web services in java
Web services in javaWeb services in java
Web services in java
 
WINDOWS COMMUNICATION FOUNDATION
WINDOWS COMMUNICATION FOUNDATIONWINDOWS COMMUNICATION FOUNDATION
WINDOWS COMMUNICATION FOUNDATION
 
Web services
Web servicesWeb services
Web services
 
WCF and WF in Framework 3.5
WCF and WF in Framework 3.5WCF and WF in Framework 3.5
WCF and WF in Framework 3.5
 
Jasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-casJasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-cas
 
Consul: Service Mesh for Microservices
Consul: Service Mesh for MicroservicesConsul: Service Mesh for Microservices
Consul: Service Mesh for Microservices
 
What is new in WCF 4.0?
What is new in WCF 4.0?What is new in WCF 4.0?
What is new in WCF 4.0?
 
Understanding Web Services by software outsourcing company india
Understanding Web Services by software outsourcing company indiaUnderstanding Web Services by software outsourcing company india
Understanding Web Services by software outsourcing company india
 
SOA patterns
SOA patterns SOA patterns
SOA patterns
 
Top wcf interview questions
Top wcf interview questionsTop wcf interview questions
Top wcf interview questions
 
Wcf best practice
Wcf best practiceWcf best practice
Wcf best practice
 
Decompose That WAR! Architecting for Adaptability, Scalability, and Deployabi...
Decompose That WAR! Architecting for Adaptability, Scalability, and Deployabi...Decompose That WAR! Architecting for Adaptability, Scalability, and Deployabi...
Decompose That WAR! Architecting for Adaptability, Scalability, and Deployabi...
 
Net Services
Net ServicesNet Services
Net Services
 
Dot Net Training Wcf Dot Net35
Dot Net Training Wcf Dot Net35Dot Net Training Wcf Dot Net35
Dot Net Training Wcf Dot Net35
 
Complete Architecture and Development Guide To Windows Communication Foundati...
Complete Architecture and Development Guide To Windows Communication Foundati...Complete Architecture and Development Guide To Windows Communication Foundati...
Complete Architecture and Development Guide To Windows Communication Foundati...
 
Web Service Basics and NWS Setup
Web Service  Basics and NWS SetupWeb Service  Basics and NWS Setup
Web Service Basics and NWS Setup
 

Recently uploaded

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Recently uploaded (20)

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

10 Tricks and Tips for WCF

  • 1. Top 10 Tricks & Tips for WCF Barry Dorrans http://idunno.org
  • 2. About the Speaker (the ego slide) MVP – Visual Tools, Security barryd@idunno.org
  • 3. Agenda 1) The test harnesses 2) Don’t use Using 3) It’s all your fault 4) Migrating an ASMX 5) Message Inspectors 6) Custom Authentication 7) Port sharing 8) Callbacks 9) Logging 10) RESTful services
  • 4. What is WCF? Indigo Replaces Web Services, WSE & Remoting Interoperability
  • 5. The ABCs of WCF Address Binding Contract
  • 6. Service Model Client Server Messaging Layer Endpoint Address Binding Channel Behaviour Behaviour Contract Binding Binding Channel Behaviour Behaviour Factory Listener Channel Address Address Channel *
  • 7. Address scheme:// <machineName>[:port]/path http://localhost:8080/Account/ net.tcp://localhost:8080/Account
  • 8. Binding How you communicate with a service A service may have multiple bindings Defines the shape; security etc.
  • 9. Contract The external interface Contracts for service, data and message
  • 10. The ABCs Address = WHERE Binding = HOW Contract = WHAT
  • 11. Service Contracts [ServiceContract()] public interface IMyService { [OperationContract] string MyOperation1(string myValue); [OperationContract] string MyOperation2(MyDataContract value); }
  • 12. Data Contracts [DataContract] public class MyDataContract { string _stuff; [DataMember] public string Stuff { get { return _stuff; } set { stuff = value; } } }
  • 13. 1 – The test harnesses
  • 14. 2 – Don’t use Using
  • 15. Disposing the right way Service1Client proxy = null; try { proxy = new Service1Client(....); } catch (...) finally { if (proxy != null) { try { if (proxy.State == CommunicationState.Opened) proxy.Close(); else if (proxy.State == CommunicationState.Faulted) proxy.Abort(); } catch (CommunicationException) { proxy.Abort(); } catch (TimeoutException) { proxy.Abort(); } } }
  • 16. 3 - It’s all your fault
  • 17. Faults the right way In Contract Code [ServiceContract] public interface IService1 { [OperationContract] [FaultContract(typeof(NegativeNumberFault))] string GetDataWithFault(int value); } [DataContract] public class NegativeNumberFault { } In Service Code throw new FaultException<NegativeNumberFault>( new NegativeNumberFault(), new FaultReason(quot;value was negativequot;)); In Client Code try { .... } catch (FaultException<NegativeNumberFault>) { .... }
  • 18. 4 – Migrating an ASMX
  • 19. Migrating an ASMX 1. Change the protocol binding to basicHttpBinding 2. Match your namespaces [ServiceContract(Namespace=quot;http:/tempuri.org/quot;)] 3. Match your actions [OperationContract(Action = quot;http://tempuri.org/HelloWorldquot;)] 4. Match your message names (if you use them) [OperationContract(Action = quot;http://tempuri.org/HelloWorldquot;, Name = quot;MyMessageNamequot;)] 5. Change the serializer to use XmlSerializer [XmlSerializerAttribute] public class MyService
  • 20. Migrating an ASMX 6. Make WCF answer ASMX <buildProviders> <remove extension=quot;.asmxquot;/> <add extension=quot;.asmxquot; type=quot;System.ServiceModel.Activation.ServiceBuildProvider, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089quot;/> </buildProviders>
  • 21. 5 – Message Inspectors
  • 22. Message Inspectors 1. Can be client or server side 2. Messages can be modified – but you must copy the message then replace it. 3. Apply the custom behaviour via config or via an attribute.
  • 23. 6 – Custom Authentication
  • 24. Custom Authentication 1. Reference System.IdentityModel and System.IdentityModel.Selectors 2. Implement a UsernamePasswordValidator 3. Plug it in via config
  • 25. 7 – Port Sharing
  • 26. Port Sharing 1. Vista / Windows 2008 – netsh http add urlacl url=http://+:port/url/ user=Everyone 2. XP / Windows 2003 (Support Tools)– httpcfg set urlacl /u http://*:80/url/ /a D:(A;;GX;;;NS) 3. XP does not port share with IIS.
  • 28. Callbacks 1. Publish / Subscribe model works best 2. Declare a callback interface interface IMessageCallback { [OperationContract(IsOneWay = true)] void OnMessageAdded(string message, DateTime timestamp); } 3. Add the callback to the service contract. [ServiceContract(CallbackContract = typeof(IMessageCallback))] 4. Implement callback interface on client.
  • 30. 10 – RESTful services
  • 31. RESTful services 1. Reference System.ServiceModel.Web 2. Use WebHttpBinding and WebHttpBehavior 3. Decorate contract with WebGet or WebInvoke [OperationContract] [WebInvoke(Method = quot;POSTquot;, UriTemplate = quot;quot;)] void AddMessage(Message message); [OperationContract] [WebInvoke(Method = quot;DELETEquot;, UriTemplate = quot;{id}quot;)] void DeleteMessage(string id); [OperationContract] [WebGet(UriTemplate = quot;{id}quot;)] Message GetMessage(string id); [OperationContract] [WebGet(UriTemplate = quot;quot;)] List<Message> GetMessages();
  • 32. RESTful services 4. Avoid the hassle and use the REST starter kit http://msdn.microsoft.com/en-us/netframework/wcf/rest