Advertisement
Guest User

Untitled

a guest
Apr 17th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1.     [TestFixture]
  2.     public class Web
  3.     {
  4.         public const string baseAddress = "http://localhost:8080/v1.0";
  5.         IHello wc;
  6.         WebServiceHost ws;
  7.  
  8.         [SetUp]
  9.         public void Init()
  10.         {
  11.             #region server
  12.             var bind = new WebHttpBinding ();
  13.             ws = new WebServiceHost (typeof (HelloDataServer), new Uri (baseAddress));
  14.  
  15.             bind.TransferMode = TransferMode.Streamed;
  16.             ws.AddServiceEndpoint (typeof (IHello), bind, "");
  17.             ws.Open ();
  18.             #endregion
  19.  
  20.             #region client
  21.             var address = new EndpointAddress(new Uri(baseAddress));
  22.             var binding = new WebHttpBinding();
  23.             var factory = new ChannelFactory<IHello>(binding, address);
  24.  
  25.             factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
  26.             wc = factory.CreateChannel();
  27.             #endregion
  28.         }
  29.  
  30.         [TearDown]
  31.         public void End()
  32.         {
  33.             ((IClientChannel)wc).Close();          
  34.             ws.Close ();
  35.         }
  36.  
  37.         [Test]
  38.         public void SayHello()
  39.         {
  40.             const string message = "Hello there";
  41.  
  42.             Assert.Equals(message, wc.PostHello(message));
  43.         }
  44.     }
  45.  
  46.  
  47.     [ServiceContract]
  48.     public interface IHello
  49.     {
  50.         [OperationContract]
  51.         [WebInvoke(UriTemplate = "greetz",
  52.             RequestFormat= WebMessageFormat.Json,  
  53.             ResponseFormat = WebMessageFormat.Json,
  54.             BodyStyle = WebMessageBodyStyle.Bare,
  55.             Method = "POST")]
  56.         string PostHello(string message);
  57.     }
  58.  
  59.     class WebClient : System.ServiceModel.ClientBase<IHello>, IHello
  60.     {
  61.         string IHello.PostHello (string message)
  62.         {
  63.             return base.Channel.PostHello (message);
  64.         }
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement