using System; using System.Text; using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.ServiceModel; using WCFService; using System.Threading; using System.ServiceModel.Description; using System.ServiceModel.Web; using ServiceContracts; namespace Test { public class WCFRESTServiceClientFixture { private AutoResetEvent stopFlag = new AutoResetEvent(false); private AutoResetEvent startedFlag = new AutoResetEvent(false); protected string endPoint = "http://localhost:5843"; private void RunService() { stopFlag.Reset(); startedFlag.Reset(); var svh = new WebServiceHost(typeof(Service1)); svh.AddServiceEndpoint( typeof(IService1), new WebHttpBinding(), endPoint ); svh.Open(); Console.WriteLine("SERVER - Running..."); startedFlag.Set(); stopFlag.WaitOne(); Console.WriteLine("SERVER - Shutting down..."); svh.Close(); Console.WriteLine("SERVER - Shut down"); } Thread serviceThread = null; public virtual void Initialize() { // start server serviceThread = new Thread(RunService); serviceThread.IsBackground = true; serviceThread.Start(); startedFlag.WaitOne(); //var channelFactory = new ChannelFactory<IService1>(new WebHttpBinding(), endPoint); //channelFactory.Endpoint.Behaviors.Add(new WebHttpBehavior()); //client = channelFactory.CreateChannel(); } protected IService1 client = null; public virtual void Cleanup() { //var clientCon = client as IClientChannel; //if(clientCon != null) // clientCon.Close(); stopFlag.Set(); if(serviceThread != null) serviceThread.Join(); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)