|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionWCF default debugging does not support edit and continue features, as I have said in my blog post BackgroundIn that post I said that there is an easy way to do it, but I didn't give any code. So this article is about how to it. The reason I wrote this article, is because a fellow member wrote a usefull article about wcf, and in tip1 he suggested using a console application. My scenario for wcf service consuming and debugging is a Client Server application. I believe my solution can apply and for other scenarios. How to do itYou need this class internal class DebugServiceHost:IDisposable
{
private static string serviceExecuteTypeName = "ServiceSide.ExecutionService.ServiceExecute, ServiceSide.ExecutionService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
private static string iServiceExecuteTypeName = "ServiceSide.ExecutionService.IServiceExecute, ServiceSide.ExecutionService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
public static string Address = @"%22http://localhost:9999/ExecutionService/ServiceExecute/%22">http://localhost:9999/ExecutionService/ServiceExecute/";
public static Binding Binding = new WSHttpBinding();
static DebugServiceHost()
{
isEnabled = Type.GetType(serviceExecuteTypeName) != null;
}
public DebugServiceHost()
{
Type serviceType = Type.GetType(serviceExecuteTypeName);
Type iServiceType = Type.GetType(iServiceExecuteTypeName);
this.debugHost = new ServiceHost(serviceType);
this.debugHost.AddServiceEndpoint(iServiceType, Binding, Address);
this.debugHost.Open();
}
private System.ServiceModel.ServiceHost debugHost;
private static bool isEnabled = false;
public static bool IsEnabled
{
get { return isEnabled; }
}
#region IDisposable Members
private bool disposed = false;
public void Dispose()
{
if (this.disposed)
{
return;
}
this.debugHost.Close();
GC.SuppressFinalize(this);
}
#endregion
}
where Using the codeI use a provider class, but its up to you how to implement the above feature.
This a sample code from my project that consumed the true or debug hosted service. public static class Provider
{
private static DebugServiceHost dbh;
public static void CheckAndRunDebugService()
{
if (DebugServiceHost.IsEnabled)
{
dbh = new DebugServiceHost();
}
}
public static string RemoteURL { get; set; }
private static IServiceExecute iServiceExecute = null;
private static IServiceExecute GetInterface()
{
if (iServiceExecute != null)
return iServiceExecute;
iServiceExecute = CreateClient();
return iServiceExecute;
}
private static ServiceExecuteClient CreateClient()
{
string address = "";
if (DebugServiceHost.IsEnabled)
{
address = DebugServiceHost.Address;
}
else
{
address = String.Format("{0}/Service.svc", Provider.RemoteURL);
}
return new ServiceExecuteReference.ServiceExecuteClient("DefaultEndPoint", address);
}
}
where
Points of InterestAt first I at the first call to the service, I create the host. But as I mentioned in my post there was problem with that implementation.
So I refactored the code, and at the program main entry method I call Final thing is that, you must implement a trick in order for all serverside assemblies to be found in the client execution folder when you are debugging. There are a number of ways to do achieve this mainly by using post build event or by just adding the references and deleting them when in deployment face. I use the first. ApologiesThere is not project code, because the above resides in a framework project, I have written for the company I work for.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||