Load operation failed for query 'GetUser'. 远程服务器返回了错误: NotFound。
Silverlight Business Application 项目,新增一个WCF Service,取名为TestWcfService,其中定义操作数据库的方法.Silverlight中增加服务引用,将项目发布到IIS
现在的情形:
在IE中键入:http://localhost/SilverlightWcf/Services/TestWcfService.svc,可以访问.
在项目中,TestWcfService右键在浏览器中查看,可以正常显示.但是运行项目报错信息如下:
System.ServiceModel.CommunicationException was unhandled by user code
Message=尝试向 URI“http://localhost/SilverlightWcf/Services/TestWcfService.svc”发出请求时出错。这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP 服务。您可能需要与该服务的所有者联系,以发布跨域策略文件并确保该文件允许发送 SOAP 相关的 HTTP 标头。出现此错误也可能是由于使用的是 Web 服务代理中的内部类型而没有使用 InternalsVisibleToAttribute 属性。有关详细信息,请参阅内部异常。
StackTrace:
位于 System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
位于 System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
位于 System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
位于 BusinessWcfApplication.Silverlight.IISService.TestWcfServiceClient.TestWcfServiceClientChannel.EndSelectSGUser(IAsyncResult result)
位于 BusinessWcfApplication.Silverlight.IISService.TestWcfServiceClient.BusinessWcfApplication.Silverlight.IISService.ITestWcfService.EndSelectSGUser(IAsyncResult result)
位于 BusinessWcfApplication.Silverlight.IISService.TestWcfServiceClient.OnEndSelectSGUser(IAsyncResult result)
位于 System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
InnerException: System.Security.SecurityException
Message=""
StackTrace:
位于 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
位于 System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
位于 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
InnerException: System.Security.SecurityException
Message=安全性错误。
StackTrace:
位于 System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
位于 System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
位于 System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__1(Object sendState)
InnerException:
在IIS中访问页面报错如下:
Load operation failed for query 'GetUser'.远程服务器返回了错误:NotFound
位于 System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.End(IAsyncResult result)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.<>c__DisplayClass1.<HandleAsyncCompleted>b__0(Object state)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.RunInSynchronizationContext(SendOrPostCallback callback, Object state)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.HandleAsyncCompleted(IAsyncResult asyncResult)
位于 System.ServiceModel.DomainServices.Client.AsyncResultBase.Complete()
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.WebAuthenticationService.HandleOperationComplete(OperationBase operation)
位于 System.ServiceModel.DomainServices.Client.LoadOperation.<>c__DisplayClass4`1.<Create>b__0(LoadOperation`1 arg)
位于 System.ServiceModel.DomainServices.Client.LoadOperation`1.InvokeCompleteAction()
位于 System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
位于 System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
位于 System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
位于 System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )
Caused by: Load operation failed for query 'GetUser'. 远程服务器返回了错误: NotFound。
位于 System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.End(IAsyncResult result)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.<>c__DisplayClass1.<HandleAsyncCompleted>b__0(Object state)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.RunInSynchronizationContext(SendOrPostCallback callback, Object state)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.HandleAsyncCompleted(IAsyncResult asyncResult)
位于 System.ServiceModel.DomainServices.Client.AsyncResultBase.Complete()
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.WebAuthenticationService.HandleOperationComplete(OperationBase operation)
位于 System.ServiceModel.DomainServices.Client.LoadOperation.<>c__DisplayClass4`1.<Create>b__0(LoadOperation`1 arg)
位于 System.ServiceModel.DomainServices.Client.LoadOperation`1.InvokeCompleteAction()
位于 System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
位于 System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
位于 System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
位于 System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )
Caused by: Load operation failed for query 'GetUser'. 远程服务器返回了错误: NotFound。
位于 System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.End(IAsyncResult result)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.<>c__DisplayClass1.<HandleAsyncCompleted>b__0(Object state)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.RunInSynchronizationContext(SendOrPostCallback callback, Object state)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.HandleAsyncCompleted(IAsyncResult asyncResult)
位于 System.ServiceModel.DomainServices.Client.AsyncResultBase.Complete()
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.WebAuthenticationService.HandleOperationComplete(OperationBase operation)
位于 System.ServiceModel.DomainServices.Client.LoadOperation.<>c__DisplayClass4`1.<Create>b__0(LoadOperation`1 arg)
位于 System.ServiceModel.DomainServices.Client.LoadOperation`1.InvokeCompleteAction()
位于 System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
位于 System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
位于 System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
位于 System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )
Caused by: Load operation failed for query 'GetUser'. 远程服务器返回了错误: NotFound。
位于 System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.End(IAsyncResult result)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.<>c__DisplayClass1.<HandleAsyncCompleted>b__0(Object state)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.RunInSynchronizationContext(SendOrPostCallback callback, Object state)
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationOperation.HandleAsyncCompleted(IAsyncResult asyncResult)
位于 System.ServiceModel.DomainServices.Client.AsyncResultBase.Complete()
位于 System.ServiceModel.DomainServices.Client.ApplicationServices.WebAuthenticationService.HandleOperationComplete(OperationBase operation)
位于 System.ServiceModel.DomainServices.Client.LoadOperation.<>c__DisplayClass4`1.<Create>b__0(LoadOperation`1 arg)
位于 System.ServiceModel.DomainServices.Client.LoadOperation`1.InvokeCompleteAction()
位于 System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
位于 System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
位于 System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
位于 System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )
网上找了一堆都不得解,求解决方案
[解决办法]
一、在WCF项目根目录下添加clientaccesspolicy.xml文件
请参考这篇文章。
http://www.cnblogs.com/akiing/archive/2009/11/17/1604489.html
[解决办法]
添加2个跨域文件到你的项目中,2个xml文件,名称及其内容如下。
1、clientaccesspolicy.xml<?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 include-subpaths="true" path="/"/> </grant-to> </policy> </cross-domain-access></access-policy>2、CrossDomain.xml<?xml version="1.0"?><!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>