Programming services-slides
Upcoming SlideShare
Loading in...5
×
 

Programming services-slides

on

  • 695 views

 

Statistics

Views

Total Views
695
Views on SlideShare
695
Embed Views
0

Actions

Likes
0
Downloads
8
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Programming services-slides Programming services-slides Presentation Transcript

  •           
  •    public abstract class Message : IDisposable { // numerous overloads for creating messages public static Message CreateMessage(...); // reads the body as XML public XmlDictionaryReader GetReaderAtBodyContents(); // deserializes the body into a .NET object public T GetBody<T>(XmlObjectSerializer serializer); // numerous methods/overloads for writing messages public void WriteMessage(XmlDictionaryWriter writer); ... }
  •     
  •    [DataContract] public class Invoice { [DataMember] public string CustomerId; [DataMember] private DateTime InvoiceDate; public string SomePrivateData; ... }
  •     [ServiceContract] public interface IInvoiceService { [OperationContract(IsOneWay=true)] void SubmitInvoice(Invoice invoice); [OperationContract] InvoiceStatus GetStatus(Invoice invoice); void CancelInvoice(Invoice invoice); }
  •   [ServiceBehavior( InstanceContextMode=InstanceContextMode.Single, ConcurrencyMode=ConcurrencyMode.Multiple)] public class InvoiceService : IInvoiceService { [OperationBehavior( Impersonation=ImpersonationOption.Required)] public void SubmitInvoice(Invoice invoice) { ... // implementation omitted } ... }
  •     
  • class Program { static void Main(string[] args) { ServiceHost host = new ServiceHost(typeof(InvoiceService)); ... // configure the host before opening try { host.Open(); Console.ReadLine(); host.Close(); } catch (Exception e) { Console.WriteLine(e); host.Abort(); } } } <%@ ServiceHost Service="InvoiceService" %>
  •  
  •    <configuration> <system.serviceModel> <!-- this is where you configure your WCF applications --> </system.serviceModel> </configuration>
  •   ... host.AddServiceEndpoint( typeof(IInvoiceService), new BasicHttpBinding(), "http://server/invoiceservice"); host.AddServiceEndpoint( typeof(IInvoiceService), new NetTcpBinding(), "net.tcp://server:8081/invoiceservice"); host.Open(); ...
  • <configuration> <system.serviceModel> <services> <service name="InvoiceService"> <endpoint address="http://server/invoiceservice" binding="basicHttpBinding" contract="IInvoiceService"/> <endpoint address="net.tcp://server:8081/invoiceservice" binding="netTcpBinding" contract="IInvoiceService"/> </service> </services> </system.serviceModel> </configuration>
  •     
  •  BasicHttpBinding b = new BasicHttpBinding(); b.Security.Mode = BasicHttpSecurityMode.Transport; b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; host.AddServiceEndpoint( typeof(IInvoiceService), b, "http://server/invoiceservice"); ...
  • <configuration> <system.serviceModel> <services> <service name="InvoiceService"> <endpoint address="https://server/invoiceservice" binding="basicHttpBinding" bindingConfiguration="MyBindingConfiguration" contract="IInvoiceService"/> ... </service> </services> <bindings> <basicHttpBinding> <binding name="MyBindingConfiguration"> <security mode="Transport"> <transport clientCredentialType="Basic" /> </security> </binding> </basicHttpBinding> </bindings> </system.serviceModel> </configuration>
  •    
  •   ... ServiceHost host = new ServiceHost(typeof(InvoiceService)); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; host.Description.Behaviors.Add(smb); host.Open(); ...
  • <configuration> <system.serviceModel> <services> <service name="InvoiceService" behaviorConfiguration="MetadataBehavior"> ... </service> </services> <behaviors> <serviceBehaviors> <behavior name="MetadataBehavior"> <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
  •       <configuration> <system.serviceModel> <services> <service name="InvoiceService" behaviorConfiguration="MetadataBehavior"> <endpoint address="net.tcp://server:80801/invoiceservice/mex" binding="mexTcpBinding" contract="IMetadataExchange"/> ...
  •     <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <s:Fault> <faultcode xmlns:a="..." xmlns="">a:InternalServiceFault</faultcode> <faultstring xml:lang="en-US" xmlns="">The server was unable to process the request due to an internal error...</faultstring> </s:Fault> </s:Body> </s:Envelope>
  •    <configuration> <system.serviceModel> <behaviors> <behavior name="Default"> <serviceDebug includeExceptionDetailInFaults="true" /> </behaviors> </behaviors> </system.serviceModel> </configuration>
  •     ... public void DoSomething(string input) { ... throw new FaultException("Something bad happened"); }
  •         
  •        