Wednesday, August 29, 2012

Silverlight Cross-domain issue with WCF self-hosted in windows service

Silverlight Cross-domain issue with WCF self-hosted in windows service

I have a Silverlight application that is running perfectly in my local machine, consuming WCF services form a development server (self-hosted in windows services).

I have to debug one of the WCF services, in order to find the root cause of a bug. I added my debug/tracing info in the service, and installed in a virtual machine (and even locally), but since then, I get the well-known cross-domain error:

"An error occurred while trying to make a request to URI 'http://MyVMMachine:4096/MyService'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details."

That's strange, because if consuming from a dev server, it works fine, but if installing the service in a dev machine, or even locally (self-hosted in windows service as well), it doesn't work.

Here is the service original code:

public partial class WindowsService : ServiceBase {     ServiceHost _Host;      public WindowsService()     {         try         {             InitializeComponent();         }         catch (Exception exc)         {             Server.One.Log("Windows service initialization failed: " + exc.Message);         }     }      protected override void OnStart(string[] args)     {         try         {             Server.One.Start();             _Host = new ServiceHost(typeof(Service));             _Host.Open();         }         catch (Exception exc)         {             Server.One.Log("Windows service start failed: " + exc.Message);         }     }      protected override void OnStop()     {         try         {             if (_Host != null)                 _Host.Close();             Server.One.Stop();         }         catch (Exception exc)         {             Server.One.Log("Windows service stop failed: " + exc.Message);         }     } } 

After reading Carlos Figueira's article on this subject, I changed the service applying his approach, but still not working.

Any ideas???

Thanks!

Answers & Comments...

Answer: 1

Try with fiddler to see where is your application really asking for your service.

This has happened to me a couple of times and it usually was because of server port changes 8-)

Just change your ServiceReferences.ClientConfig to the server port.

Take a look at your Service project configuration (web tab) and set the specific port as 4096 if you want to call it there:

enter image description here

by : zapicohttp://stackoverflow.com/users/694693




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog