Cross domain error in WCF wsHttpBindingwith silverlight

2.2k views Asked by At

I have a WCF service and I am using wsHttpBinding in web.config.

I have also created a test certificate from IIS7 and used it for https binding with website

Web config of Service as below

<system.serviceModel>
  <behaviors>
   <serviceBehaviors>
    <behavior name="WsBehaviour">
     <serviceMetadata httpsGetEnabled="true"/>
     <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
   </serviceBehaviors>
  </behaviors>

  <bindings>
   <wsHttpBinding>
    <binding name="WsBinding">
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="None" algorithmSuite="Default" />        
      </security>            
    </binding>
   </wsHttpBinding>    
  </bindings>

  <services>
   <service name="WsService.Service1" behaviorConfiguration ="WsBehaviour">
     <endpoint address="https://MachineName.DomainName:8087/WsService/Service1.svc"
      binding="wsHttpBinding" bindingConfiguration="WsBinding" contract="WsService.IService1" >

       <identity>
         <dns value="localhost" />
       </identity>

     </endpoint>
   </service>
  </services>  
 </system.serviceModel>

When I open the URL in a browser it works perfectly, and also works perfectly when I add a Service reference to the silverlight project.

But when I call the service from the application it gives a cross-domain error.

I have also include clientaccesspolicy.xml and crossDomain.xml in the project, but still face a problem

An error occurred while trying to make a request to URI
'https://MachineName.DomainName:8087/WsService/Service1.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. 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.

enter image description here

2

There are 2 answers

1
Rob J On

The clientaccesspolicy.xml needs to be in the root directory of your web server, not in your project.

http://msdn.microsoft.com/en-us/library/cc197955(v=vs.95).aspx

3.Save the crossdomain.xml file to the root of the domain where the service is hosted. If, for example, the service is hosted in http://fabrikam.com, then the file must be located at http://fabrikam.com/crossdomain.xml

0
Talha Imam On

You need to add clientaccesspolicy.xml and crossDomain.xml in the root folder of the WCF service which you re hosting on IIS.