views:

665

answers:

1

Dear all,

I have a WCF Service that I've added to a Silverlight project and is now hosting in Visual Studio's ASP.NET Dev Server. But tyring to run it I get the following error:

System.ServiceModel.CommunicationException was unhandled by user code
  Message="An error occurred while trying to make a request to URI 'http://localhost:51547/WCFService1/Service.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."
  StackTrace:
       at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
       at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
       at niki_lanik_latestnews.WCFXmlOps.IxmlLoadClient.IxmlLoadClientChannel.EndLoadArticleFromXML(IAsyncResult result)
       at niki_lanik_latestnews.WCFXmlOps.IxmlLoadClient.niki_lanik_latestnews.WCFXmlOps.IxmlLoad.EndLoadArticleFromXML(IAsyncResult result)
       at niki_lanik_latestnews.WCFXmlOps.IxmlLoadClient.OnEndLoadArticleFromXML(IAsyncResult result)
       at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
  InnerException: System.Security.SecurityException
       Message=""
       StackTrace:
            at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
            at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
            at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
       InnerException: System.Security.SecurityException
            Message="Security error."
            StackTrace:
                 at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
                 at System.Net.Browser.BrowserHttpWebRequest.c__DisplayClass5.b__4(Object sendState)
                 at System.Net.Browser.AsyncHelper.c__DisplayClass2.b__0(Object sendState)
            InnerException: 

It's not hosted cross domain as it's in the same project, so I'm not sure what is causing this? Any ideas anyone?

Tony

UPDATE

Below is my binding config in web.config:

     <bindings>
  <basicHttpBinding>
   <binding name="basicHTTP" 
             receiveTimeout="00:10:00" 
             sendTimeout="00:10:00" 
             closeTimeout="00:10:00" 
             openTimeout="00:03:00" 
             maxBufferSize="100000" 
             maxReceivedMessageSize="100000" 
             transferMode="StreamedResponse">

    </binding>
  </basicHttpBinding>
 </bindings>
 <services>
  <service behaviorConfiguration="mexBehavior" name="LoadXMLService.XMLOperations">
   <endpoint address="" 
              binding="basicHttpBinding" 
              bindingConfiguration="basicHTTP" 
              contract="LoadXMLService.IxmlLoad" />
  </service>
 </services>

Please remember this service is supposed download & upload files to the Silerlight 3 project.

+2  A: 

I would suggest adding the file "clientaccesspolicy.xml" to your website root with the following contents (at least as a troubleshooting step). The error that you are receiving seems to suggest this will help.

It is my understanding that Silverlight considers cross-port calls to be cross-domain (i.e. localhost:51547 and localhost:4000 are different domains).

<?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>

[Edit]

Well, the first thing to get it working is to be able to connect directly to the hosted service, so I'll throw out some ideas of issues I ran into.

Do you have this line in your service?

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService
{
}

and this line in the Web.Config?

<system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
</system.serviceModel>
Timothy Lee Russell