Skip to main content
Home Forums Silverlight Programming Programming with .NET - General CrossDomain problem
9 replies. Latest Post by davidezordan on October 28, 2008.
(0)
Rasto
Member
1 points
6 Posts
10-28-2008 6:57 AM |
Hi
I have a simple WCF service hosted in console application. Then I have a cross domain policy file provider service.
When I call the service from silverlight I get this exception
An error occurred while trying to make a request to URI 'http://localhost:8011/SimpleService'. 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.
even clientaccesspolicy.xml was send back with status 200. I checked it with Web Development Helper in IE7.
Here is the clientaccesspolicy.xml
<access-policy> <cross-domain-access> <policy> <allow-from> <domain uri="http//*"/> </allow-from> <grant-to> <resource path="/" include-subpaths="true"/> </grant-to> </policy> </cross-domain-access></access-policy>
Any ideas what could be wrong?
davidezo...
Contributor
5690 points
875 Posts
10-28-2008 7:13 AM |
Hi,
as reported here http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx
<?xml version="1.0" encoding="utf-8"?> <access-policy> <cross-domain-access> <policy> <allow-from http-request-headers="*"> <domain uri="*"/> </allow-from> <grant-to> <resource path="/" include-subpaths="true"/> </grant-to> </policy> </cross-domain-access> </access-policy>
Have a nice day,
10-28-2008 8:13 AM |
I updated the xml file but still the same exception.
Please check the configuration.
My Silverlight ServiceReferences.ClientConfig
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_ISimpleService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <security mode="None"/> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost:8011/ISimpleService" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISimpleService" contract="SimpleServiceProxy.ISimpleService" name="BasicHttpBinding_ISimpleService" /> </client> </system.serviceModel>
My service app.config
<system.serviceModel> <services> <service name="CrossDomain"> <host> <baseAddresses> <add baseAddress="http://localhost:8011/" /> </baseAddresses> </host> <endpoint address="" binding="webHttpBinding" contract="Interfaces.ICrossDomain" behaviorConfiguration="HttpEnableBehavior" /> </service> <service behaviorConfiguration="SimpleService.Service1Behavior" name="SimpleService"> <host> <baseAddresses> <add baseAddress="http://localhost:8011/SimpleService"/> </baseAddresses> </host> <endpoint address="http://localhost:8011/SimpleService" binding="basicHttpBinding" contract="Interfaces.ISimpleService"> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <endpointBehaviors> <behavior name="HttpEnableBehavior"> <webHttp/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="SimpleService.Service1Behavior"> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
10-28-2008 8:25 AM |
Have you tried to consume the service using a WPF or WinForm client? In this way you can check if it's a cross-domain issue or a service-related problem.
10-28-2008 8:37 AM |
Yes, I tried. The WPF client works.
Could some WCF or Silverlight security settings cause the problem?
10-28-2008 8:43 AM |
You should now trace the calls using a tool like Fiddler just to verify if the clientaccesspolicy.xml is found and then if the service is correctly called by the Silverlight client.
10-28-2008 9:58 AM |
I published the generated test page from Visual Studio on IIS and it works.
It doesn't work when I run the project from Visual Studio 2008. Why?
10-28-2008 10:24 AM |
Have you tried to insert the clientaccesspolicy.xml in the root of your Visual Studio wcf project?
10-28-2008 11:12 AM |
Yes, I tried. The file was in every folder.
I think, when WCF service is hosted in console application it doesn't matter where the file is.
Now I have it in code
public Message ProvidePolicyFile() { TextReader reader = new StringReader(@"<?xml version='1.0' encoding='utf-8'?><access-policy> <cross-domain-access> <policy> <allow-from http-request-headers='*'> <domain uri='*'/> </allow-from> <grant-to> <resource path='/' include-subpaths='true'/> </grant-to> </policy> </cross-domain-access></access-policy>"); return Message.CreateMessage(MessageVersion.None, "", XmlReader.Create(reader)); }
I looked in the http log. The xml is in the response.
Any other ideas?
10-28-2008 11:24 AM |
You can take a look at this article which describes WCF hosted in console applications and Silverlight http://www.dotnetcurry.com/(X(1)S(dstdn1vd34hpuhz3f0av0r55))/ShowArticle.aspx?ID=208&AspxAutoDetectCookieSupport=1Hope%20this%20helps,