WCF服务异常

时间:2010-03-28 15:35:44

标签: wcf web-services

我目前正在开发一个Silverlight 3项目,我正在使用2台机器进行测试。

“harbinger”是运行Win7 + IIS的Web服务器。我已将网页和WCF Web服务部署到该计算机。

我在浏览器中输入了以下网址:

http://harbinger:43011/UserService.svc
http://harbinger:43011/UserService.svc?wsdl

并且页面加载了两者的预期内容

接下来我决定检查我是否可以从我的机器上调用web服务,我已经添加了ServiceReference,执行了对其中一个方法的调用,然后.... BOOM:

System.ServiceModel.CommunicationException was unhandled by user code
  Message="An error occurred while trying to make a request to URI 'http://harbinger:43011/UserService.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 Energy.USR.UserServiceClient.UserServiceClientChannel.EndGetAllUsers(IAsyncResult result)
       at Energy.USR.UserServiceClient.Energy.USR.UserService.EndGetAllUsers(IAsyncResult result)
       at Energy.USR.UserServiceClient.OnEndGetAllUsers(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.<EndGetResponse>b__4(Object sendState)
                 at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
            InnerException: 

有人可以解释刚刚发生了什么吗?我需要做些什么来避免这种情况?

1 个答案:

答案 0 :(得分:2)

请参阅此博文 - 我认为这是您问题的根本原因:

Enabling cross-domain calls for Silverlight apps on self-hosted web services

或者这个:

WCF and Silverlight with cross-domain issue

如果没有任何特殊的政策文件,您将无法在Silverlight中调用跨域。