none
My Silverlight application cannot access my service

    Question

  • Hello all,

    I've run into a lot of problems with Silverlight and WCF Services, and I've managed to resolve them all in the end someway or another, but this one has me stumped.

    For the 1st time I have seperated my WCF service from the Silverlight applicatin solution and now I have this nightmare. Everything I read points to cross-domain policy issues, and I have followed all of them to the letter, including http://timheuer.com/blog/archive/2008/04/09/silverlight-cannot-access-web-service.aspx to no avail.

    Exception: An error occurred while trying to make a request to URI 'http://localhost:1844/WebSvc.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.

    Inner Exception stack trace:

    {System.Security.SecurityException ---> System.Security.SecurityException: Security error.
       at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
       at System.Net.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
       at System.Net.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
       --- End of inner exception stack trace ---
       at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
       at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)}

    clientaccesspolicy.xml


    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="true">
            <domain uri="*"/>
          </allow-from>
          <grant-to>
            <resource include-subpaths="true" path="/"/>
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>

     One thing I have not tried is a domainpolicy.xml file - will this solve this issue? Where can I find more info on what this files does / needs to contain etc.?

    Thanks,

    Sean

    Thursday, December 11, 2008 10:22 AM

All replies

  • So lets try a couple things.  With your project running can you manually access the service?  Go into IE and just type in the URL: http://localhost:1844/WebSvc.svc.  Does that work?

    If that doesn't work then there is something wrong with the service itself.  You could have a messed up Services.clientconfig file (the file in your Silverlight application) where it points to where the WCF service URI is.  Make sure that is pointing to the URI above.

    If it is a clientaccesspolicy.xml file, what you can do is make sure the file is on the root of the service.  So, the file needs to be located at: http://localhost:1844/clientacesspolicy.xml  (you can try that URL manually in the browser)

    If both those things work, try the Web DevelopMent Helper and enbable logging and then profile the requests in your Silverlight page when it starts.  This will give you the requests/responses for the crossdomainpolicy file and the request/response to the service:

    http://projects.nikhilk.net/WebDevHelper/

    Thursday, December 11, 2008 10:30 AM
  • Hi,

    Thanks for the reply. I've tried all of the above.

    The Web Dev Helper tools shows the request/response for the clientaccesslpolicy.xml file only. Its a GET request that returns the clientaccesslpolicy.xml is the response. Then the app crashes with the same error message, but no more logging data can be seen in web dev helper.

     Anyone any ideas?

    Sunday, December 14, 2008 5:03 AM
  • nobody have an idea as to what else may cause this exception

    Sunday, December 14, 2008 5:05 AM
  • So I've ended up having to add the WCF Service to the Silverlight web project, which works fine as usual.

    This is fine for the minute for testing on localhost but when it comes to deployment i'm going to have the same problem.

    I've ticked all the boxes - I can access the Service AND the clientaccesspolicy.xml from IE, and Web Developer Helper returns HTTP 200 on the Get request for the clientaccesspolicy.xml. As soon as the Get request has been completed the service crahses with the cross-domain policy exception shown in the initial post, suggesting a problem with the content of the clientaccesspolicy.xml, but again, I cannot see any problem, maybe someone else can??

     

    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="true">
            <domain uri="*"/>
          </allow-from>
          <grant-to>
            <resource include-subpaths="true" path="/"/>
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>
     
    Tuesday, December 16, 2008 3:23 AM
  • This is a bit of a nightmare. Is there no other explanation for this error?

    Wednesday, December 17, 2008 12:04 PM
  • You can zip it up and send me your solution and I would be glad to take a look at it.

    Wednesday, December 17, 2008 12:45 PM
  • I am having the same problem. I originally solved it by puttin the service in the web application. However, I have now created a test application that is, of course, not in the same web application with the web service. WebDevHelper shows me clientaccesspolicy.xml return 200, but no further http is logged. I have tried copies of several clientaccesspolicy.xml files, all of them appear identical. Is it possible that the application has some kind of real security error that is identified after the xml file is found?

    Thursday, December 18, 2008 11:37 AM
  • I'm having the same issue, in my case the hosting provider company, exposes the services in a different URL:

    •  I have added the clientaccesspolicy file.
    • Checked with fiddler that is downloaded fine (HTTP 200).
    • Then my application crashes.

    The only tip that I see is that in exception it says something about SOAP headers, does it has something to do?

    Thanks

      Braulio

    Monday, December 22, 2008 11:59 AM
  • So I've ended up having to add the WCF Service to the Silverlight web project, which works fine as usual.

    This is fine for the minute for testing on localhost but when it comes to deployment i'm going to have the same problem.

    I've ticked all the boxes - I can access the Service AND the clientaccesspolicy.xml from IE, and Web Developer Helper returns HTTP 200 on the Get request for the clientaccesspolicy.xml. As soon as the Get request has been completed the service crahses with the cross-domain policy exception shown in the initial post, suggesting a problem with the content of the clientaccesspolicy.xml, but again, I cannot see any problem, maybe someone else can??

    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="true">
            <domain uri="*"/>
          </allow-from>
          <grant-to>
            <resource include-subpaths="true" path="/"/>
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>

     

    Can you try with a simple clientaccesspolicy.xml file?

    I see that you set http-request-headers value to "true", try to put a "*" value first.

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

     

    Friday, December 26, 2008 11:06 AM
  • I'm having the same issue, in my case the hosting provider company, exposes the services in a different URL:

    •  I have added the clientaccesspolicy file.
    • Checked with fiddler that is downloaded fine (HTTP 200).
    • Then my application crashes.

    The only tip that I see is that in exception it says something about SOAP headers, does it has something to do?

    Thanks

      Braulio

    Silverlight supports only SOAP v1.1 in basicHttpBinding mode

    A typical workaround in a B2B context is to create a WCF service in your web application that re-exposes the web service you are attempting to reach, see this post for more details :

    http://blogs.msdn.com/silverlight_plus_java/archive/2008/07/31/b2b-scenario-partner-env.aspx

     

    Friday, December 26, 2008 11:14 AM
  •  Hi Sean,

     Did you have any luck with this error? I am also getting the same error. My service is hosted on 64-bit OS machine. Do you think that will make any difference?

     Thanks!

     

    Friday, January 02, 2009 12:59 PM
  •  Hi Sean,

    I do not know whether or not you have both clientaccesspolicy.xml and crossdomain.xml at your root but in my case it turned out that I had both clientaccesspolicy.xml and crossdomain.xml at my root. I went and deleted crossdomain.xml and everything started working magically! One of the forum users pointed this out.

    HTH

     

    Friday, January 02, 2009 1:23 PM
  • I cant find crossdomain.xml anywhere in the output directories so its either an embedded resource or missing from my app I guess.

    Sunday, January 04, 2009 6:30 AM
  • I have had the same problem for several weeks and the post above fixed it for me.

    Here is my answer:

    My old clienaccesspolicy.xml file was:

    <?xml version="1.0" encoding="utf-8" ?>

    <access-policy>

    <cross-domain-access>

    <policy>

    <allow-from http-request-headers="true">

    <domain uri="*"/>

    </allow-from>

    <grant-to>

    <resource include-subpaths="true" path="/"/>

    </grant-to>

    </policy> </cross-domain-access>

    </access-policy>

     My new one:

    <?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 include-subpaths="true" path="/"/>

    </grant-to>

    </policy> </cross-domain-access>

    </access-policy>

    Notice the "<allow-from http-request-headers="*">" with an asterick instead of true, THAT SOLVED THE ISSUE.
    Tuesday, January 06, 2009 7:53 PM
  • That is not my problem. My file looks lke your new one. Glad you found your issue.

    Wednesday, January 07, 2009 12:48 PM
  • Same issue only things were working find until I added some control and code, not sure related but will post if I find anything.

    Update: look here http://silverlight.net/forums/p/63815/157594.aspx#157594

    I had http://localhost:1182/ServiceName.svc for my service reference address and it when when I updated it with http://localhost:1330/ServiceName.svc?wsdl

     Got that from clicking on the service URL on top of header page http://localhost:1182/ProNet.svc

    Sunday, January 11, 2009 12:18 PM
  • It's been some months since this thread dead-ended, but just in case you haven't found a solution.  This link describes one that worked for me (I had the exact same problem you had.  http://wallism.wordpress.com/tag/cross-domain/

     Cheers,

    Mark

    Tuesday, July 07, 2009 11:34 AM