Silverlight 3.6 cross-domain error

Silverlight 3.6 cross-domain error

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


KingTuck68 posted on Saturday, October 25, 2008

Hi,

I've gotten the entire Rolodex project setup and built successfully. After I get to the login screen, enter User/user and click the login button, I get this exception:

System.ServiceModel.CommunicationException was unhandled by user code
  Message="An error occurred while trying to make a request to URI 'http://localhost:2430/WcfPortal.svc'. 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. Please see the inner exception for more details."


Anybody know how to get around this? The cross-domain xml files are all there, so I'm not sure why it's not working. I am loading this up and running with file system type access with Cassini.

Thanks much!

JoeFallon1 replied on Sunday, October 26, 2008

"... Cassini."

My guess is that if you used IIS you would not have this problem.

Not sure how you configure Cassini to use a known port - but that may be part of this issue. It keeps changing ports as you start up.

Joe

 

sergeyb replied on Sunday, October 26, 2008

I think in Rolodex port is hard-coded to avoid the issue with Cassini.  This project should run just fine in Cassini, as this is how it was developed.  The likeliest problem in database connection string.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

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

 

From: JoeFallon1 [mailto:cslanet@lhotka.net]
Sent: Sunday, October 26, 2008 11:28 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] Silverlight 3.6 cross-domain error

 

"... Cassini."

My guess is that if you used IIS you would not have this problem.

Not sure how you configure Cassini to use a known port - but that may be part of this issue. It keeps changing ports as you start up.

Joe

 



RockfordLhotka replied on Sunday, October 26, 2008

I suspect the most common cause of this problem is that you aren't running the web site, but rather you are running the Silverlight app project. Right-click on the web project in Solution Explorer and set it as the startup project.

What happens otherwise, is that VS creates a temporary web page to run the Silverlight project directly, so it runs in its own instance of the web server. Of course the app then tries to communicate with the web project - which is a different web server (and thus is cross-domain) and that fails because we don't have a cross-domain access file in the web project.

KingTuck68 replied on Monday, October 27, 2008

Rocky wins the prize! Setting the right startup seems to be the problem! I'm getting invalid logins for all the users now instead of the previous error. I'll do some debugging, but I have another question:

There are two connection strings in the host web.config. Do both get used or just one? I have the database setup to use SQL Server Developer and the first entry seemed to be the one, so I commented the other out. Is this correct?

Thanks!

sergeyb replied on Monday, October 27, 2008

That is fine.  There are two connection strings there to demonstrate the user of SQL Express attach DB functionality as well as SQL Server.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

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

 

From: KingTuck68 [mailto:cslanet@lhotka.net]
Sent: Monday, October 27, 2008 9:14 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Silverlight 3.6 cross-domain error

 

Rocky wins the prize! Setting the right startup seems to be the problem! I'm getting invalid logins for all the users now instead of the previous error. I'll do some debugging, but I have another question:

There are two connection strings in the host web.config. Do both get used or just one? I have the database setup to use SQL Server Developer and the first entry seemed to be the one, so I commented the other out. Is this correct?

Thanks!


sergeyb replied on Sunday, October 26, 2008

Pretty much all errors in SL are reported as 404, including DB errors.  The first thing is to very that DB access is correct.  Check web.config in wcf project and verify that connection corresponds to your machine’s setup.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

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

 

From: KingTuck68 [mailto:cslanet@lhotka.net]
Sent: Saturday, October 25, 2008 10:35 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Silverlight 3.6 cross-domain error

 

Hi,

I've gotten the entire Rolodex project setup and built successfully. After I get to the login screen, enter User/user and click the login button, I get this exception:

System.ServiceModel.CommunicationException was unhandled by user code
  Message="An error occurred while trying to make a request to URI 'http://localhost:2430/WcfPortal.svc'. 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. Please see the inner exception for more details."


Anybody know how to get around this? The cross-domain xml files are all there, so I'm not sure why it's not working. I am loading this up and running with file system type access with Cassini.

Thanks much!



fedge replied on Tuesday, November 25, 2008

Anyone else fixed this? I've made sure my sql express db path is OK< but still getting error.

'http://localhost:2430/WcfPortal.svc' also reports ok -

You have created a service.

To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:


 

svcutil.exe http://localhost:2430/WcfPortal.svc?wsdl

This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:

C#

class Test
{
    static void Main()
    {
        WcfPortalClient client = new WcfPortalClient();

        // Use the 'client' variable to call operations on the service.

        // Always close the client.
        client.Close();
    }
}


 

Visual Basic

Class Test
    Shared Sub Main()
        Dim client As WcfPortalClient = New WcfPortalClient()
        ' Use the 'client' variable to call operations on the service.

        ' Always close the client.
        client.Close()
    End Sub
End Class

 

 

fedge replied on Tuesday, November 25, 2008

please ignore previous, I got stuck mid thread and never saw everyones replies! doh! wrong start up project, sorry

RockfordLhotka replied on Tuesday, November 25, 2008

Silverlight has specific rules about calling services.

 

It can call a service from the same domain where the xap file originated (where it was downloaded from).

 

It can call a service in another domain only if the root of that domain has a cross domain policy file granting permission to make the call.

 

When running most of our Silverlight samples, I have noticed that Visual Studio often chooses the wrong default startup application when you first load a solution. By default, it seems to pick the Silverlight application project, not the web site project.

 

The trick is that Visual Studio WILL run the Silverlight application directly – it just creates a temporary web page to host the xap. But that web page is now hosted in a different web server (different domain) from the web site project. So when the Silverlight app tries to talk to the web site app (where the service is located) you get a cross domain error.

 

The solution is simple – just make sure Visual Studio is set so the web site project is the default startup project.

 

Rocky

Copyright (c) Marimer LLC