220 likes | 442 Views
Introducing WCF Services. WCF. Programming Model. SOAP Services. Workflow Services. Web HTTP Services. Data Services. RIA Services. Service Model. Data Contract. Service Contract. Service Behavior. Channel Model. Formats (Atom, JSON, XML,…). Transports (HTTP, TCP, …). Protocols
E N D
WCF Programming Model SOAPServices Workflow Services Web HTTP Services Data Services RIA Services Service Model Data Contract Service Contract Service Behavior Channel Model Formats (Atom, JSON, XML,…) Transports (HTTP, TCP, …) Protocols (SOAP, HTTP, Open Data Protocol,…)
WCF is the way to build services on the .NET Framework ASMX is limiting WCF is powerful • HTTP-only hosting in IIS • Tightly coupled implementation & interface • No support for security, guaranteed delivery, transactions, binary serialization • Advanced scenarios require mixing models • highly configurable and highly extensible • supports what ASMX cannot • supports a unified programming model across all protocols ASMX is at the end of what it can do with “HelloWorld” WCF 4 makes “HelloWorld” easy & extends to other scenarios Only WCF Services can leverage AppFabric
Host (IIS | AppFabric) Service Implementation (MyCalc: ICalculator) Key Service Concepts Data Contract Service Contract (ICalculator) Operations (implementation) double Add(double a, double b) double GetArea(Rectangle r) Operations (signatures) double Add(double a, double b) double GetArea(Rectangle r) Rectangle double width, double height • Host • Service Implementation • Service Contract • Data Contract • Service Endpoint (Address, Binding Contract) • Service Behavior Service Configuration (web.config) Service Behaviors (Metadata) Service Endpoint Address (http://localhost/MyCalc.svc) Binding(basicHttp) Service Contract (ICalculator)
Key WCF 4 Configuration Features • File-Less (Config Based) Activation <serviceActivations> <add relativeAddress="Calculator.svc" service="Microsoft.ServiceModel.Samples.CalculatorService" /> <serviceActivations> • Inheritance Model for Configuration • Default Protocol Mapping <protocolMapping> <add scheme="http" binding="wsHttpBinding" /> </protocolMapping>
Key Client Concepts Client Proxy Instance (MyCalcClient) proxy.Add(5,2) Client Configuration (app.config) Client Endpoint • Proxy • Endpoints • Messages • Service Instance Address (http://localhost/MyCalc.svc) Binding(basicHttp) Service Contract (ICalculator) Send Message Receive Message 7 Add(5,2) Service Instance
Best Practice Proxy Use CalculatorClient proxy = new CalculatorClient(); Try { proxy.Add(1,5); proxy.Close(); } Catch (Exception ex) { proxy.Abort(); throw; }
Tracked Events Normal Operation: ServiceHost events Aggregates for Operations Completed Calls Troubleshooting:Throttling Service Exceptions User Defined Errors Failed Calls Faulted Calls
Emitting User Defined Errors DiagnosticSection config = (DiagnosticSection) WebConfigurationManager.GetSection("system.serviceModel/diagnostics"); providerId = new Guid(config.EtwProviderId); myEventProvider = new EventProvider(providerId); errorDescriptor = new EventDescriptor(ErrorEventId, Version, Channel, ErrorLevel, Opcode, Task, Keywords); error event id's 301,302,303 mean error, warning, info respectively myEventProvider.WriteEvent(ref errorDescriptor, title, serviceName, errorMessage); WCFUserEventProvider eventWriter = new WCFUserEventProvider();eventWriter.WriteErrorEvent(“AddOperation”, “An error occurred.”); Get the ETW Provider ID Create a new Event Provider for that ID Define an event descriptor Write the event We provide a sample that encapsulates all this into just:
Lab 2 • Introducing WCF Services