Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [TestFixture]
- public class Web
- {
- public const string baseAddress = "http://localhost:8080/v1.0";
- IHello wc;
- WebServiceHost ws;
- [SetUp]
- public void Init()
- {
- #region server
- var bind = new WebHttpBinding ();
- ws = new WebServiceHost (typeof (HelloDataServer), new Uri (baseAddress));
- bind.TransferMode = TransferMode.Streamed;
- ws.AddServiceEndpoint (typeof (IHello), bind, "");
- ws.Open ();
- #endregion
- #region client
- var address = new EndpointAddress(new Uri(baseAddress));
- var binding = new WebHttpBinding();
- var factory = new ChannelFactory<IHello>(binding, address);
- factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
- wc = factory.CreateChannel();
- #endregion
- }
- [TearDown]
- public void End()
- {
- ((IClientChannel)wc).Close();
- ws.Close ();
- }
- [Test]
- public void SayHello()
- {
- const string message = "Hello there";
- Assert.Equals(message, wc.PostHello(message));
- }
- }
- [ServiceContract]
- public interface IHello
- {
- [OperationContract]
- [WebInvoke(UriTemplate = "greetz",
- RequestFormat= WebMessageFormat.Json,
- ResponseFormat = WebMessageFormat.Json,
- BodyStyle = WebMessageBodyStyle.Bare,
- Method = "POST")]
- string PostHello(string message);
- }
- class WebClient : System.ServiceModel.ClientBase<IHello>, IHello
- {
- string IHello.PostHello (string message)
- {
- return base.Channel.PostHello (message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement