SlideShare a Scribd company logo
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 Introduction
WCF IntroductionWCF Introduction
WCF Introduction
Mohamed Zakarya Abdelgawad
 
WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)
ipower softwares
 
Wcf
WcfWcf
WCF
WCFWCF
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
Jorgen Thelin
 
WCF And ASMX Web Services
WCF And ASMX Web ServicesWCF And ASMX Web Services
WCF And ASMX Web Services
Manny Siddiqui MCS, MBA, PMP
 
Windows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Best PracticesWindows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Best Practices
Orbit One - We create coherence
 
WCF tutorial
WCF tutorialWCF tutorial
WCF tutorial
Abhi Arya
 
Introduction to WCF
Introduction to WCFIntroduction to WCF
Introduction to WCF
ybbest
 
Beginning with wcf service
Beginning with wcf serviceBeginning with wcf service
Beginning with wcf service
Binu Bhasuran
 
introduction to Windows Comunication Foundation
introduction to Windows Comunication Foundationintroduction to Windows Comunication Foundation
introduction to Windows Comunication Foundation
redaxe12
 
WCF
WCFWCF
Windows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) ServiceWindows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) Service
Sj Lim
 
1. WCF Services - Exam 70-487
1. WCF Services - Exam 70-4871. WCF Services - Exam 70-487
1. WCF Services - Exam 70-487
Bat 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 API
Kevin 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 & SOAPUI
Advancio
 
Session 1: The SOAP Story
Session 1: The SOAP StorySession 1: The SOAP Story
Session 1: The SOAP Story
ukdpe
 
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
Peter 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 Services
ecosio 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
 
Nosql ve mongoDB
Nosql ve mongoDBNosql ve mongoDB
Nosql ve mongoDB
Saygın Topatan
 
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
 
Making WCF Simple
Making WCF SimpleMaking WCF Simple
Making WCF Simple
Jesus Rodriguez
 
Project Management with SharePoint 2010
Project Management with SharePoint 2010Project Management with SharePoint 2010
Project Management with SharePoint 2010
Greg Kiefer
 
C# Advanced L08-Networking+WCF
C# Advanced L08-Networking+WCFC# Advanced L08-Networking+WCF
C# Advanced L08-Networking+WCF
Mohammad 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
 
Web Service Security
Web Service SecurityWeb Service Security
Web Service Security
n|u - The Open Security Community
 
Burpsuite yara
Burpsuite yaraBurpsuite yara
Burpsuite yara
Rinaldi Rampen
 
Building single page applications
Building single page applicationsBuilding single page applications
Building single page applications
SC5.io
 
Pentesting RESTful WebServices v1.0
Pentesting RESTful WebServices v1.0Pentesting RESTful WebServices v1.0
Pentesting RESTful WebServices v1.0
n|u - The Open Security Community
 
Pentesting ReST API
Pentesting ReST APIPentesting ReST API
Pentesting ReST API
Nutan Kumar Panda
 
Advanced WCF Workshop
Advanced WCF WorkshopAdvanced WCF Workshop
Advanced WCF Workshop
Ido 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 Comparison
Adnan Masood
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
Volkan Uzun
 
Аналитические решения в телекомах. Презентация с киевского мероприятия 27.09.12
Аналитические решения в телекомах. Презентация с киевского мероприятия 27.09.12Аналитические решения в телекомах. Презентация с киевского мероприятия 27.09.12
Аналитические решения в телекомах. Презентация с киевского мероприятия 27.09.12
Alexey Kononenko
 
отчёт Антикризис
отчёт Антикризисотчёт Антикризис
отчёт АнтикризисunDrei
 
Capodian Investment Management
Capodian Investment ManagementCapodian Investment Management
Capodian Investment Management
AnthonySchnur
 

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

WCF 4 Overview
WCF 4 OverviewWCF 4 Overview
WCF 4 Overview
Mariano Omar Rodriguez
 
Wcf
Wcf Wcf
Wcf faq
Wcf faqWcf faq
Wcf faq
Rajoo Jha
 
A presentation on WCF & REST
A presentation on WCF & RESTA presentation on WCF & REST
A presentation on WCF & REST
Santhu Rao
 
Web services in java
Web services in javaWeb services in java
Web services in java
maabujji
 
WINDOWS COMMUNICATION FOUNDATION
WINDOWS COMMUNICATION FOUNDATIONWINDOWS COMMUNICATION FOUNDATION
WINDOWS COMMUNICATION FOUNDATION
Deepika Chaudhary
 
Web services
Web servicesWeb services
Web services
aspnet123
 
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
ukdpe
 
Jasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-casJasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-cas
ellentuck
 
Consul: Service Mesh for Microservices
Consul: Service Mesh for MicroservicesConsul: Service Mesh for Microservices
Consul: Service Mesh for Microservices
ArmonDadgar
 
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 india
Jignesh Aakoliya
 
SOA patterns
SOA patterns SOA patterns
SOA patterns
Arnon Rotem-Gal-Oz
 
Top wcf interview questions
Top wcf interview questionsTop wcf interview questions
Top wcf interview questions
tongdang
 
Wcf best practice
Wcf best practiceWcf best practice
Wcf best practice
Yu 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
 
Net Services
Net ServicesNet Services
Net Services
rsnarayanan
 
Dot Net Training Wcf Dot Net35
Dot Net Training Wcf Dot Net35Dot Net Training Wcf Dot Net35
Dot Net Training Wcf Dot Net35
Subodh 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
 
Web Service Basics and NWS Setup
Web Service  Basics and NWS SetupWeb Service  Basics and NWS Setup
Web Service Basics and NWS Setup
Northeastern University
 

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

Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 

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