【问题标题】:An error occurred while trying to make a request to URI http://localhost:XXXXX/XXXX尝试向 URI http://localhost:XXXX/XXXX 发出请求时出错
【发布时间】:2016-08-17 14:45:45
【问题描述】:

我正在使用包含 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)}

【问题讨论】:

    标签: wcf c#-4.0 visual-studio-2013 sharepoint-2013 silverlight-5.0


    【解决方案1】:

    我通过这种方式解决了我的问题。如果您通过 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

    【讨论】:

      【解决方案2】:

      最后,我找到了解决问题的方法。 当我尝试从客户端系统上的页面访问 silverlight 按钮时出现此错误。这是因为 localhost 无法在客户端机器中获取 ClientAccessPolicy.xml 和 CrossDomainPolicy.xml。

      解决这个问题的方法是将ClientAccessPolicy.xml和CrossDomainPolicy.xml复制到客户端机器的根目录下,同时最好的方法是通过WCF或者WPF服务将策略文件发送到localhost用作服务参考的 URL。

      有关如何发送 ClientAccessPolicy.xml 和 CrossDomainPolicy.xml 的参考,请参阅这些链接。

      https://blogs.msdn.microsoft.com/carlosfigueira/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services/

      https://code.msdn.microsoft.com/Accessing-self-hosted-WCF-7872c931

      感谢和问候

      哈沙

      【讨论】:

        猜你喜欢
        • 2021-11-15
        • 1970-01-01
        • 2022-06-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多