Programming clients-slides

929 views
772 views

Published on

Published in: Education, Business, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
929
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Programming clients-slides

  1. 1.      
  2. 2.   
  3. 3.     
  4. 4.    
  5. 5.    
  6. 6.
  7. 7.    ChannelFactory<IInvoiceService> cf = new ChannelFactory<IInvoiceService>(endpoint); ...
  8. 8.  ChannelFactory<IInvoiceService> factory = new ChannelFactory<IInvoiceService>( new BasicHttpBinding(), new EndpointAddress("http://server/invoiceservice")); ... ChannelFactory<IInvoiceService> factory = new ChannelFactory<IInvoiceService>("httpEndpoint"); ...
  9. 9. <configuration> <system.serviceModel> <client> <endpoint name="httpEndpoint" address="http://server/invoiceservice" binding="basicHttpBinding" contract="IInvoiceService"/> <endpoint name="tcpEndpoint" address="net.tcp://server:8081/invoiceservice" binding="netTcpBinding" contract="IInvoiceService"/> </client> </system.serviceModel> </configuration>
  10. 10.    ChannelFactory<IInvoiceService> factory = new ChannelFactory<IInvoiceService>("tcpEndpoint"); IInvoiceService channel = factory.CreateChannel(); channel.SubmitInvoice(invoice); ((IClientChannel)channel).Close();
  11. 11.         
  12. 12.     public interface IInvoiceServiceChannel : IInvoiceService, System.ServiceModel.IClientChannel { } ChannelFactory<IInvoiceServiceChannel> factory = new ChannelFactory<IInvoiceServiceChannel>("tcpEndpoint"); IInvoiceServiceChannel channel = factory.CreateChannel(); channel.SubmitInvoice(invoice); channel.Close();
  13. 13.     public partial class InvoiceServiceClient : ClientBase<IInvoiceService>, IInvoiceService { public InvoiceServiceClient() { } public InvoiceServiceClient(string endpointName) : base(endpointName) { } ... // you're service contract methods will be here
  14. 14. ... InvoiceServiceClient client = new InvoiceServiceClient("httpEndpoint"); Invoice invoice = new Invoice(); invoice.CustomerName = "Acme, Inc"; invoice.Amount = 100.00; invoice.InvoiceDate = DateTime.Now; client.SubmitInvoice(invoice); client.Close(); ...
  15. 15.      
  16. 16. <configuration> <system.serviceModel> <client> <endpoint name="httpEndpoint" address="http://server/invoiceservice" binding="basicHttpBinding" bindingConfiguration="MyConfiguration" contract="InvoiceServiceReference.IInvoiceService" /> </client> <bindings> <basicHttpBinding> <binding name="MyConfiguration" sendTimeout="00:05:00"> <security mode="Transport"> <transport clientCredentialType="Basic"/> </security> </binding> </basicHttpBinding> </bindings> </system.serviceModel> </configuration>
  17. 17. <configuration> <system.serviceModel> <client> <endpoint name="httpEndpoint" address="http://server/invoiceservice" binding="basicHttpBinding" behaviorConfiguration="viaBehavior" contract="InvoiceServiceReference.IInvoiceService" /> </client> <behaviors> <endpointBehaviors> <behavior name="viaBehavior"> <clientVia viaUri="http://router/invoiceservice"/> </behavior> </endpointBehaviors> </behaviors> ...
  18. 18.
  19. 19. InvoiceServiceClient client = new InvoiceServiceClient("httpEndpoint"); Invoice invoice = ... // create invoice try { client.SubmitInvoice(invoice); client.Close(); } catch (FaultException fe) { Console.WriteLine(fe); client.Abort(); } catch (CommunicationException ce) { Console.WriteLine(ce); client.Abort(); } catch (TimeoutException te) { Console.WriteLine(te); client.Abort(); } ...
  20. 20.       
  21. 21.     
  22. 22.    
  23. 23.        
  24. 24.          

×