Skip to main content

Microsoft Silverlight

Answered Question CrossDomain problemRSS Feed

(0)

Rasto
Rasto

Member

Member

1 points

6 Posts

CrossDomain problem

 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?

davidezordan
davidezo...

Contributor

Contributor

5690 points

875 Posts

Silverlight MVP

Re: CrossDomain problem

Hi,
as reported here http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx 
you should have to modify the clientaccesspolicy.xml file:
<?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,

Thanks, Davide

Silverlight MVP

Blog Twitter Silverlight Experts

Rasto
Rasto

Member

Member

1 points

6 Posts

Re: CrossDomain problem

 Hi,

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>

davidezordan
davidezo...

Contributor

Contributor

5690 points

875 Posts

Silverlight MVP

Re: Re: CrossDomain problem

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.

 

Thanks, Davide

Silverlight MVP

Blog Twitter Silverlight Experts

Rasto
Rasto

Member

Member

1 points

6 Posts

Re: Re: CrossDomain problem

 Yes, I tried. The WPF client works.

Could some WCF or Silverlight security settings cause the problem?

davidezordan
davidezo...

Contributor

Contributor

5690 points

875 Posts

Silverlight MVP

Re: Re: Re: CrossDomain problem

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.

Thanks, Davide

Silverlight MVP

Blog Twitter Silverlight Experts

Rasto
Rasto

Member

Member

1 points

6 Posts

Re: Re: Re: CrossDomain problem

I published the generated test page from Visual Studio on IIS and it works.Smile

It doesn't work when I run the project from Visual Studio 2008. Why? 

davidezordan
davidezo...

Contributor

Contributor

5690 points

875 Posts

Silverlight MVP

Re: Re: Re: Re: CrossDomain problem

Have you tried to insert the clientaccesspolicy.xml in the root of your Visual Studio wcf project?

Thanks, Davide

Silverlight MVP

Blog Twitter Silverlight Experts

Rasto
Rasto

Member

Member

1 points

6 Posts

Re: Re: Re: Re: CrossDomain problem

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? 

davidezordan
davidezo...

Contributor

Contributor

5690 points

875 Posts

Silverlight MVP
Answered Question

Re: Re: Re: Re: Re: CrossDomain problem

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,

Thanks, Davide

Silverlight MVP

Blog Twitter Silverlight Experts
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities