Successfully reported this slideshow.

Programming services-slides

1,061 views

Published on

Published in: Education, Technology, Business
  • Be the first to comment

  • Be the first to like this

Programming services-slides

  1. 1.           
  2. 2.
  3. 3.    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); ... }
  4. 4.     
  5. 5.    [DataContract] public class Invoice { [DataMember] public string CustomerId; [DataMember] private DateTime InvoiceDate; public string SomePrivateData; ... }
  6. 6.     [ServiceContract] public interface IInvoiceService { [OperationContract(IsOneWay=true)] void SubmitInvoice(Invoice invoice); [OperationContract] InvoiceStatus GetStatus(Invoice invoice); void CancelInvoice(Invoice invoice); }
  7. 7.   [ServiceBehavior( InstanceContextMode=InstanceContextMode.Single, ConcurrencyMode=ConcurrencyMode.Multiple)] public class InvoiceService : IInvoiceService { [OperationBehavior( Impersonation=ImpersonationOption.Required)] public void SubmitInvoice(Invoice invoice) { ... // implementation omitted } ... }
  8. 8.
  9. 9.     
  10. 10. 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" %>
  11. 11.  
  12. 12.    <configuration> <system.serviceModel> <!-- this is where you configure your WCF applications --> </system.serviceModel> </configuration>
  13. 13.   ... host.AddServiceEndpoint( typeof(IInvoiceService), new BasicHttpBinding(), "http://server/invoiceservice"); host.AddServiceEndpoint( typeof(IInvoiceService), new NetTcpBinding(), "net.tcp://server:8081/invoiceservice"); host.Open(); ...
  14. 14. <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>
  15. 15.     
  16. 16.
  17. 17.
  18. 18.  BasicHttpBinding b = new BasicHttpBinding(); b.Security.Mode = BasicHttpSecurityMode.Transport; b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; host.AddServiceEndpoint( typeof(IInvoiceService), b, "http://server/invoiceservice"); ...
  19. 19. <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>
  20. 20.    
  21. 21.   ... ServiceHost host = new ServiceHost(typeof(InvoiceService)); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; host.Description.Behaviors.Add(smb); host.Open(); ...
  22. 22. <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>
  23. 23.       <configuration> <system.serviceModel> <services> <service name="InvoiceService" behaviorConfiguration="MetadataBehavior"> <endpoint address="net.tcp://server:80801/invoiceservice/mex" binding="mexTcpBinding" contract="IMetadataExchange"/> ...
  24. 24.     <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>
  25. 25.    <configuration> <system.serviceModel> <behaviors> <behavior name="Default"> <serviceDebug includeExceptionDetailInFaults="true" /> </behaviors> </behaviors> </system.serviceModel> </configuration>
  26. 26.     ... public void DoSomething(string input) { ... throw new FaultException("Something bad happened"); }
  27. 27.         
  28. 28.        

×