Guest User

Untitled

a guest
Aug 11th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. [ServiceContract]
  2. public interface IService
  3. {
  4. [OperationContract]
  5. string Invoke(string input);
  6. }
  7.  
  8. public class Service : IService
  9. {
  10. public string Invoke(string input)
  11. {
  12. return input;
  13. }
  14. }
  15.  
  16. public class OperationSelector : IDispatchOperationSelector
  17. {
  18. public string SelectOperation(ref Message message)
  19. {
  20. return "Invoke";
  21. }
  22. }
  23.  
  24. public class EndpointBehavior : IEndpointBehavior
  25. {
  26. public void Validate(ServiceEndpoint endpoint)
  27. { }
  28.  
  29. public void AddBindingParameters(ServiceEndpoint endpoint,
  30. BindingParameterCollection bindingParameters)
  31. { }
  32.  
  33. public void ApplyDispatchBehavior(ServiceEndpoint endpoint,
  34. EndpointDispatcher endpointDispatcher)
  35. {
  36. endpointDispatcher.DispatchRuntime.OperationSelector = new OperationSelector();
  37. }
  38.  
  39. public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
  40. { }
  41. }
  42.  
  43. static void Main(string[] args)
  44. {
  45. var host = new ServiceHost(typeof(Service),
  46. new Uri("http://localhost:8000/Service.svc"));
  47. var endpoint = host.AddServiceEndpoint(typeof(IService), new BasicHttpBinding(), "");
  48. endpoint.Behaviors.Add(new EndpointBehavior());
  49. host.Open();
  50.  
  51. Console.ReadLine();
  52. host.Close();
  53. }
  54.  
  55. POST http://localhost:8000/Service.svc HTTP/1.1
  56. Content-Type: text/xml; charset=utf-8
  57. SOAPAction: "http://tempuri.org/IService/Invoke"
  58. Host: localhost:8000
  59. Expect: 100-continue
  60. Accept-Encoding: gzip, deflate
  61. Connection: Keep-Alive
  62. Content-Length: 158
  63.  
  64. <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><Invoke xmlns="http://tempuri.org/"><input>Test</input></Invoke></s:Body></s:Envelope>
  65.  
  66. [OperationContract(Action = "*")]
  67. void UnrecognizedMessageHandler(Message msg);
Advertisement
Add Comment
Please, Sign In to add comment