我正在使用包含SilverLight应用程序按钮的SharePoint登录页面,登录页面将在客户端加载,按下按钮,SilverLight应用程序必须打开客户端计算机上安装的本地WCF服务并且它必须生成OTP,但在我的情况下,这不会发生。
我正在使用的WCF Uri就像这样http://localhost:12345/service,当我按下登录页面上的按钮时,我在提琴手中注意到呼叫为http://localhost:12345/clientaccesspolicy.xml。
我已将ClientAccessPolicy.xml和CrossDomain.xml放在系统的根文件夹和项目文件夹中。
我还尝试通过WCF服务提供ClientAccessPolicy.xml,但这不起作用
以下是错误的完整堆栈跟踪。
{System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI 'http://localhost:XXXXX/XXXXX'.
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__DisplayClassa.<EndGetResponse>b__9(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<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 SLLogin.iCubeWCFsvc.Service1Client.Service1ClientChannel.EndGenKey(IAsyncResult result)
at SLLogin.iCubeWCFsvc.Service1Client.SLLogin.iCubeWCFsvc.IService1.EndGenKey(IAsyncResult result)
at SLLogin.iCubeWCFsvc.Service1Client.OnEndGenKey(IAsyncResult result)
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)}
答案 0 :(得分:1)
我这样解决了我的问题。如果您通过IIS express在本地使用该服务,请确保包含 Web服务项目的根文件夹中的ClientAccessPolicy.xml和CrossDomainPolicy.xml文件。
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>
的crossdomain.xml
<?xml version="1.0" encoding="utf-8" ?>
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="SOAPAction,Content-Type" secure="true" />
</cross-domain-policy>
参考:http://www.allenconway.net/2010/07/fixing-attempting-to-access-service-in.html
答案 1 :(得分:0)
最后,我找到了解决问题的方法。 当我尝试从客户端系统上的页面访问silverlight按钮时出现此错误。这是因为localhost无法在客户端计算机中获取ClientAccessPolicy.xml和CrossDomainPolicy.xml。
此问题的解决方案是将ClientAccessPolicy.xml和CrossDomainPolicy.xml复制到客户端计算机的根文件夹中,同时最好的方法是将策略文件通过WCF或WPF服务发送到localhost用作服务参考的URL。
有关如何发送ClientAccessPolicy.xml和CrossDomainPolicy.xml的参考,请参阅以下链接。
https://code.msdn.microsoft.com/Accessing-self-hosted-WCF-7872c931
谢谢&amp;此致
戒