尝试向URI http:// localhost:XXXXX / XXXX发出请求时发生错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了尝试向URI http:// localhost:XXXXX / XXXX发出请求时发生错误相关的知识,希望对你有一定的参考价值。
我正在使用包含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)}
我这样解决了我的问题。如果您通过IIS express在本地使用Visual Studio服务,请确保在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
最后,我找到了解决问题的方法。当我尝试从客户端系统上的页面访问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
感谢和问候
戒
以上是关于尝试向URI http:// localhost:XXXXX / XXXX发出请求时发生错误的主要内容,如果未能解决你的问题,请参考以下文章
在 Gatsby 中使用 ApolloClient 与 localhost / 本地 IP uri
出现错误:redirect_uri_mismatch 请求中的重定向 URI:http://localhost:8080/oauth2callback 与注册的重定向 URI 不匹配
允许 UIWebView 在没有 Internet 连接的情况下加载 http://localhost:port/path URI