Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 用户代码未处理CommunicationException_Silverlight_Wcf - Fatal编程技术网

Silverlight 用户代码未处理CommunicationException

Silverlight 用户代码未处理CommunicationException,silverlight,wcf,Silverlight,Wcf,我创建了一个解决方案,然后添加了一个包含所有WCF服务的项目。然后,我在同一个解决方案中添加了对我的Silverlight项目的引用。现在,当我尝试调试时,我收到一个消息框,上面说您要调试的这个Silverlight项目正在使用web服务。除非在包含web服务的web上下文中执行项目,否则对web服务的调用将失败。如果我运行它,仍然会出现以下错误:- An error occurred while trying to make a request to URI 'http://localhost

我创建了一个解决方案,然后添加了一个包含所有WCF服务的项目。然后,我在同一个解决方案中添加了对我的Silverlight项目的引用。现在,当我尝试调试时,我收到一个消息框,上面说
您要调试的这个Silverlight项目正在使用web服务。除非在包含web服务的web上下文中执行项目,否则对web服务的调用将失败。
如果我运行它,仍然会出现以下错误:-

An error occurred while trying to make a request to URI 'http://localhost:50318/CustomersService.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.
以下是详细的例外情况:-

{System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI 'http://localhost:50318/CustomersService.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. ---> System.Security.SecurityException ---> System.Security.SecurityException: Security error.
   at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
   at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
   at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
   --- End of inner exception stack trace ---
   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)
   --- End of inner exception stack trace ---
   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 MVVMDemo.CustomersServiceRef.CustomersServiceClient.CustomersServiceClientChannel.EndGetCustomers(IAsyncResult result)
   at MVVMDemo.CustomersServiceRef.CustomersServiceClient.MVVMDemo.CustomersServiceRef.ICustomersService.EndGetCustomers(IAsyncResult result)
   at MVVMDemo.CustomersServiceRef.CustomersServiceClient.OnEndGetCustomers(IAsyncResult result)
   at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)}
{System.ServiceModel.CommunicationException:尝试向URI的请求时出错http://localhost:50318/CustomersService.svc“。这可能是由于在没有适当的跨域策略或不适合SOAP服务的策略的情况下试图以跨域方式访问服务。您可能需要与ow联系。”发布跨域策略文件并确保其允许发送与SOAP相关的HTTP头的服务请求。此错误也可能是由于在web服务代理中使用内部类型而未使用InternalsVisibleToAttribute属性造成的。有关详细信息,请参阅内部异常。-->System.Security.SecurityException-->SSystem.Security.SecurityException:安全错误。
位于System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
在System.Net.Browser.BrowserHttpWebRequest.c__DisplayClass5.b__4(对象发送状态)中
在System.Net.Browser.AsyncHelper.c__DisplayClass2.b__0(对象发送状态)中
---内部异常堆栈跟踪的结束---
位于System.Net.Browser.AsyncHelper.BeginNoui(SendOrPostCallback beginMethod,对象状态)
位于System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
位于System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteTresponse(IAsyncResult结果)
---内部异常堆栈跟踪的结束---
在System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult结果)处
位于System.ServiceModel.Channels.ServiceChannel.EndCall(字符串操作,对象[]输出,IAsyncResult结果)
位于System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName,Object[]args,IAsyncResult结果)
在MVVMDemo.CustomerServiceRef.CustomerServiceClient.CustomerServiceClientChannel.EndGetCustomers(IAsyncResult结果)
在MVVMDemo.CustomersServiceRef.CustomersServiceClient.MVVMDemo.CustomersServiceRef.ICCustomersService.EndGetCustomers(IAsyncResult结果)
在MVVMDemo.CustomersServiceRef.CustomersServiceClient.onedgetcustomers(IAsyncResult结果)
在System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult结果)}
我该怎么办


提前感谢:)

如果承载silverlight控件和您尝试连接的Web服务的页面位于不同的域中(在您的情况下,它们看起来是不同的项目),则需要将clientaccesspolicy.xml文件添加到您的网站

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="SOAPAction">
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>


有关更多详细信息

Hi Vinay,我不再收到那个恼人的异常,但我确实收到了消息框。这正常吗?如果您能够使Web服务没有任何问题,那么它应该很好,但在部署应用程序时请记住这一点