When debugging a Silverlight application in Visual Studio, I get this exception:
System.ServiceModel.CommunicationException was unhandled by user code
Message=An error occurred while trying to make a request to URI 'http://localhost:8733/Design_Time_Addresses/WcfForecastService/Service1/'. 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.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
at RollingActivityForecast.Services.ForecastServiceClient.ForecastServiceClientChannel.EndGetForecasts(IAsyncResult result)
at RollingActivityForecast.Services.ForecastServiceClient.RollingActivityForecast.Services.IForecastService.EndGetForecasts(IAsyncResult result)
at RollingActivityForecast.Services.ForecastServiceClient.OnEndGetForecasts(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__DisplayClassa.<EndGetResponse>b__9(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)
InnerException:
When I deploy the application to inetpub and browse to it from within IIS Manager, it works fine with no exception, since I have put the clientaccesspolicy.xml and crossdomain.xml files with the service.
So my question is, where do I put the clientaccesspolicy.xml/crossdomain.xml files in my Visual Studio solution so I stop getting this exception when I debug?
I thought it should go in the MySilverlightApp.Web project next to the web.config file, but I still get the exception when I do this. Do I need to add something extra to the web.config file to reference the clientaccesspolicy.xml file?
FYI, I have the WCF service in a separate project from the MySilverlightApp.Web project.
TIA.
UPDATE:
Here are the files:
clientaccesspolicy.xml:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain url="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
crossdomain.xml:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
Resolved "cross-domain policy" exception by changing,
<add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfForecastService/Service1/" />
To,
<add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfForecastService/ForecastService/" />
The odd thing is, why did the service work at all on IIS with this incorrect value in the app.config file?
UPDATE:
Alternatively, you could just get rid of the separate WCF Service project and put the WCF service into the MyApp.Web project so you don't need the clientaccesspolicy.xml files at all.