Wcf System.ServiceModel.CommunicationException未被用户代码消息处理=尝试向URI发出请求时出错

Wcf System.ServiceModel.CommunicationException未被用户代码消息处理=尝试向URI发出请求时出错,wcf,silverlight,mef,Wcf,Silverlight,Mef,在Visual Studio中调试Silverlight应用程序时,出现以下异常: 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

在Visual Studio中调试Silverlight应用程序时,出现以下异常:

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: 
System.ServiceModel.CommunicationException未由用户代码处理
Message=尝试向URI的客户端发出请求时出错http://localhost:8733/Design_Time_Addresses/WcfForecastService/Service1/'. 这可能是由于在没有适当的跨域策略或不适合SOAP服务的策略的情况下,试图以跨域方式访问服务。您可能需要联系服务的所有者以发布跨域策略文件,并确保它允许发送与SOAP相关的HTTP头。此错误也可能是由于在web服务代理中使用内部类型而未使用InternalsVisibleToAttribute属性造成的。有关详细信息,请参阅内部异常。
堆栈跟踪:
在System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult结果)处
位于System.ServiceModel.Channels.ServiceChannel.EndCall(字符串操作,对象[]输出,IAsyncResult结果)
位于System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName,Object[]args,IAsyncResult结果)
在RollingActivityForecast.Services.ForecastServiceClient.ForecastServiceClientChannel.EndGetForecast(IAsyncResult结果)处
在RollingActivityForecast.Services.ForecastServiceClient.RollingActivityForecast.Services.IForecastService.EndGetForecast(IAsyncResult结果)中
在RollingActivityForecast.Services.ForecastServiceClient.OnEndGetForecast(IAsyncResult结果)处
在System.ServiceModel.ClientBase`1.OnAsyncCallCompleted处(IAsyncResult结果)
InnerException:System.Security.SecurityException
Message=“”
堆栈跟踪:
位于System.Net.Browser.AsyncHelper.BeginNoui(SendOrPostCallback beginMethod,对象状态)
位于System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
位于System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteTresponse(IAsyncResult结果)
InnerException:System.Security.SecurityException
消息=安全错误。
堆栈跟踪:
位于System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
在System.Net.Browser.BrowserHttpWebRequest.c__DisplayClassa.b__9(对象发送状态)中
在System.Net.Browser.AsyncHelper.c__DisplayClass4.b__0(对象发送状态)中
内部异常:
当我将应用程序部署到inetpub并从IIS管理器中浏览到它时,它毫无例外地工作正常,因为我已将clientaccesspolicy.xml和crossdomain.xml文件与服务放在一起

所以我的问题是,我应该将clientaccesspolicy.xml/crossdomain.xml文件放在我的Visual Studio解决方案中的什么位置,以便在调试时不再出现此异常

我认为它应该放在Web.config文件旁边的MySilverlightApp.Web项目中,但当我这样做时,仍然会出现异常。我是否需要在web.config文件中添加额外的内容来引用clientaccesspolicy.xml文件

仅供参考,我将WCF服务与MySilverlightApp.Web项目放在一个单独的项目中

蒂亚

更新:

以下是文件:

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>

要将文件包含在本地开发中,只需将跨域文件添加到解决方案文件夹(web部件),然后将其
复制到输出目录
属性更改为true

通过更改

<add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfForecastService/Service1/" />

对,


奇怪的是,为什么在app.config文件中的值不正确的情况下,该服务在IIS上工作

更新:


或者,您可以去掉单独的WCF服务项目,将WCF服务放入MyApp.Web项目中,这样您就根本不需要clientaccesspolicy.xml文件。

谢谢您的回复。是的,我忘了提到我已经将它设置为“始终复制”,但我仍然得到错误。这些文件是否应该与WCF服务位于同一目录中?
<add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfForecastService/ForecastService/" />