SlideShare ist ein Scribd-Unternehmen logo
1 von 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?

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

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