SlideShare une entreprise Scribd logo
1  sur  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?

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Dernier

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
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
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 

Dernier (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
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
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
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...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 

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