Silverlight 3, CSLA and a Windows Service

Silverlight 3, CSLA and a Windows Service

Old forum URL: forums.lhotka.net/forums/t/7803.aspx


walkerstewart posted on Friday, October 16, 2009

Hi All,

Have been working with Csla for a while now, however I have gotten to a point where I am about to throw my PC out the window.

The issue I'm having is trying to connect a Silverlight 3 app up to a CSLA 3.8.0 backend that is running as a "windows service" using basicHttpBinding.

In the debug tracing of the Silverlight app, the attempt to connect to the winservice returns a NotFound error (in the "Csla.WcfPortal.WcfPortalClientChannel" class in the "EndFetch" method (second line) within the CSLA Light library) and when I use Web Dev Helper (akin to Fiddler) to capture the response, is shows what looks to be an IIS 404 html error (below).


To show where i'm up to I have performed and tried the following:

1. Successful connection of a WPF App to my winservice running the WCF command (so I know that my Server side of things is pretty much right)
2. Configured winservice to use the Silverlight Csla DataPortal interface instead of the normal one (Csla.Server.Hosts.Silverlight.WcfPortal) (In code and config)
3. Made IIS respond to the same port as my winservice is running on ("http://localhost:8000/RIDService/RIFServerService", IIS also responds to "http://localhost:8000" (right click on website and select "Edit Bindings")) and added "clientaccesspolicy.xml" and "crossdomain.xml" to the root IIS website.
4. Enabled "includeExceptionDetailInFaults" on the server side to return errors.



My assumption is that item 3 above is causing the problem, with IIS intercepting the http requests to the 8000 port (however I can still browse and see my service at the URL above).

Note that I have not used a .svc file as it allowed for a cleaner hosting process for the rest of the application.

Could someone let me know if I can even acheive this (and if so what I may be doing wrong) or just tell me I'm stupid and that I should be using an IIS hosted .svc (I have gotten one of these working correctly also so is a possibility)?

Thanks In Advance




On Start of my Windows Service:

private Uri ServiceUri = new Uri(ConfigurationManager.AppSettings.Get("ServiceAddress"));

protected override void OnStart(string[] args)
{
try
{
// Added to pause start of thread while debugging Silverlight problem
System.Threading.Thread.Sleep(10000);

LogToDatabase("Service Starting: " + DateTime.Now.ToString());

rapServiceHost = new ServiceHost(typeof(Csla.Server.Hosts.Silverlight.WcfPortal), ServiceUri);
//rapServiceHost = new ServiceHost(typeof(WcfPortal), ServiceUri);

rapServiceHost.Open();

LogToDatabase("Service Started: " + DateTime.Now.ToString());
}
catch (Exception ex)
{
LogErrorToDatabase("Cannot start service: " + DateTime.Now.ToString(), ex.ToString());
}
}

WinService app config (sections removed for security):














openTimeout="00:05:00"
sendTimeout="00:30:00"
receiveTimeout="00:30"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647">
















binding="basicHttpBinding"
contract="Csla.Server.Hosts.Silverlight.IWcfPortal">









Silverlight ClientConfig:





sendTimeout="10"
receiveTimeout="10"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647">




binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IWcfPortal"
contract="Csla.WcfPortal.IWcfPortal"
name="BasicHttpBinding_IWcfPortal">


walkerstewart replied on Friday, October 16, 2009

Additional Screen Shot

sergeyb replied on Friday, October 16, 2009

If you can successfully connect to your service from WPF app, then this portal is not going to work for Silverlight. Silverlight and WPF actually have different portals. Even if you host a service in IIS and want both WPF and SL clients connect to it, you need to have two svc files and two endpoints - one for each application.

Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

-----Original Message-----
From: walkerstewart [mailto:cslanet@lhotka.net]
Sent: Friday, October 16, 2009 10:27 AM
To: Sergey Barskiy
Subject: [CSLA .NET] Silverlight 3, CSLA and a Windows Service

Hi All,

Have been working with Csla for a while now, however I have gotten to a point where I am about to throw my PC out the window.

The issue I'm having is trying to connect a Silverlight 3 app up to a CSLA 3.8.0 backend that is running as a "windows service" using basicHttpBinding.

In the debug tracing of the Silverlight app, the attempt to connect to the winservice returns a NotFound error (in the "Csla.WcfPortal.WcfPortalClientChannel" class in the "EndFetch" method (second line) within the CSLA Light library) and when I use Web Dev Helper (akin to Fiddler) to capture the response, is shows what looks to be an IIS 404 html error (below).


To show where i'm up to I have performed and tried the following:

1. Successful connection of a WPF App to my winservice running the WCF command (so I know that my Server side of things is pretty much right)
2. Configured winservice to use the Silverlight Csla DataPortal interface instead of the normal one (Csla.Server.Hosts.Silverlight.WcfPortal) (In code and config)
3. Made IIS respond to the same port as my winservice is running on ("http://localhost:8000/RIDService/RIFServerService", IIS also responds to "http://localhost:8000" (right click on website and select "Edit Bindings")) and added "clientaccesspolicy.xml" and "crossdomain.xml" to the root IIS website.
4. Enabled "includeExceptionDetailInFaults" on the server side to return errors.



My assumption is that item 3 above is causing the problem, with IIS intercepting the http requests to the 8000 port (however I can still browse and see my service at the URL above).

Note that I have not used a .svc file as it allowed for a cleaner hosting process for the rest of the application.

Could someone let me know if I can even acheive this (and if so what I may be doing wrong) or just tell me I'm stupid and that I should be using an IIS hosted .svc (I have gotten one of these working correctly also so is a possibility)?

Thanks In Advance




On Start of my Windows Service:

private Uri ServiceUri = new Uri(ConfigurationManager.AppSettings.Get("ServiceAddress"));

protected override void OnStart(string[] args)
{
try
{
// Added to pause start of thread while debugging Silverlight problem
System.Threading.Thread.Sleep(10000);

LogToDatabase("Service Starting: " + DateTime.Now.ToString());

rapServiceHost = new ServiceHost(typeof(Csla.Server.Hosts.Silverlight.WcfPortal), ServiceUri);
//rapServiceHost = new ServiceHost(typeof(WcfPortal), ServiceUri);

rapServiceHost.Open();

LogToDatabase("Service Started: " + DateTime.Now.ToString());
}
catch (Exception ex)
{
LogErrorToDatabase("Cannot start service: " + DateTime.Now.ToString(), ex.ToString());
}
}

WinService app config (sections removed for security):














openTimeout="00:05:00"
sendTimeout="00:30:00"
receiveTimeout="00:30"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647">
















binding="basicHttpBinding"
contract="Csla.Server.Hosts.Silverlight.IWcfPortal">









Silverlight ClientConfig:





sendTimeout="10"
receiveTimeout="10"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647">




binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IWcfPortal"
contract="Csla.WcfPortal.IWcfPortal"
name="BasicHttpBinding_IWcfPortal">




walkerstewart replied on Friday, October 16, 2009

Hi Sergey,

I agree with you on that point, however in my service I have two lines of code (just for testing at this stage), one goes to the silverlight dataportal and one to the standard dataportal:

rapServiceHost = new ServiceHost(typeof(Csla.Server.Hosts.Silverlight.WcfPortal), ServiceUri);
//rapServiceHost = new ServiceHost(typeof(WcfPortal), ServiceUri);


When I run the WPF version I change the config and change the commenting. was planning on switching based on a config thing and have the service installed twice with two different end points (Our main ERP integration will be using the NetTCP bindings so this will be the case).

As far as I can tell my config and code should work for both, but only does for the WPF side of things.

Just want to know if it is possible to integrate silverlight with CSLA with a Windows Service backend on different domains.

Thanks Again,

Stewy

sergeyb replied on Friday, October 16, 2009

OK, I did not see the different lines. I have not tried to have SL app connecting to windows service, so I am not sure what the answer is.

Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

-----Original Message-----
From: walkerstewart [mailto:cslanet@lhotka.net]
Sent: Friday, October 16, 2009 11:29 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Silverlight 3, CSLA and a Windows Service

Hi Sergey,

I agree with you on that point, however in my service I have two lines of code (just for testing at this stage), one goes to the silverlight dataportal and one to the standard dataportal:

rapServiceHost = new ServiceHost(typeof(Csla.Server.Hosts.Silverlight.WcfPortal), ServiceUri);
//rapServiceHost = new ServiceHost(typeof(WcfPortal), ServiceUri);


When I run the WPF version I change the config and change the commenting. was planning on switching based on a config thing and have the service installed twice with two different end points (Our main ERP integration will be using the NetTCP bindings so this will be the case).

As far as I can tell my config and code should work for both, but only does for the WPF side of things.

Just want to know if it is possible to integrate silverlight with CSLA with a Windows Service backend on different domains.

Thanks Again,

Stewy

Copyright (c) Marimer LLC