Like most developers trying to keep up with Microsoft technology I'm somewhat overwhelmed. I love working with the Smart Client Software Factory and Web Client Software Factory (we use them at work) and used to love being involved in the forums; unfortunately WPF, XBAP, CompositeWPF, Unity, WCF, Silverlight and SharePoint Services are on the front burner (to learn) which leaves little to no time for having fun and being involved like I could (and want to be). I should note that all of the above are my personal learning time, which I also have to share with my wife (who is my best friend). At work I'm diving into MicroStation (engineering CAD program), SQL Server 2005 Notification Services and the list goes on....
So I've abandoned the SCSF/WCSF forums (won't be blogging about them) however the following information, although left in the SCSF forum, still has great value for many of the above mentioned applications.
RightCoder wrote:
One problem I have now is that I'm not able to read the web.config file where I have my WCF-configuration. Im not sure that my MyServiceProxy in App_Code have access to the web.config?? Anyway if MyServiceProxy and BaseProxy is placed in the App_Code folder their not accessible to my modules where I have the concrete implementations of the CustomerService and SupplierService. How could this be solved?
You can use the channelFactory which will permit you to define your default end point. The using statement is important - we experienced leaks during load test without it.
public WidgetScheduleCollection GetScheduledWidgets(WidgetRequest para)
{
WidgetRequest1 request;
WidgetResponse response;
string defaultEndPoint = ConfigurationManager.AppSettings["DefaultEndPoint"].ToString();
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress endPoint = new EndpointAddress(defaultEndPoint);
// Use Channel so we don't have to rely on config file
ChannelFactory<WidgetServiceContract> channelFactory =
new ChannelFactory<WidgetServiceContract>(binding, endPoint);
WidgetServiceContract service = channelFactory.CreateChannel();
using (service as IDisposable)
{
// Wrap the request with a Channel's WidgetRequest
request = new WidgetRequest1(para);
// Get the scheduled Widgets for request
response = service.GetScheduledWidgets(request);
}
// Return the Widget collection
return response.ScheduledWidgetCollection;
}
pboldc later shares important information about using IDisposable with WCF - my response to his information follows:
pbolduc wrote:
This article was very interesting to read regarding using WCF and IDisposable etc.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=855018&SiteID=1
and a couple of MSDN links:
Avoiding Problems with the Using Statement
Expected Exceptions
Thanks for taking the time to provide these references! This topic wasn't given much emphasis in the WSSF.... After reading your links I revisited the WSSF factory forum and found that SpencerClark (Apr 4) provides wrapper code which implements the code recommended in the links - he indicates that he has "not had a single error where the service was faulted". Looks like I have a wee bit of refactoring to do on Monday ;)
If your looking to create a WCF Proxy Wrapper I would suggest reading the entire message thread here:
http://www.codeplex.com/websf/Thread/View.aspx?ThreadId=29604
Tags:
wcf
Categories: