Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 由于未访问我的客户端访问策略文件,发生了CommunicationException_Silverlight_Wcf_Clientaccesspolicy.xml - Fatal编程技术网

Silverlight 由于未访问我的客户端访问策略文件,发生了CommunicationException

Silverlight 由于未访问我的客户端访问策略文件,发生了CommunicationException,silverlight,wcf,clientaccesspolicy.xml,Silverlight,Wcf,Clientaccesspolicy.xml,我拥有托管在控制台应用程序中的WCF服务。 以下是app.config文件: <?xml version="1.0"?> <configuration> <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> <behaviors> <serviceBehaviors>

我拥有托管在控制台应用程序中的WCF服务。
以下是app.config文件:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <behaviors>
      <serviceBehaviors>
        <behavior name="CAVES.Framework.Network.IntegrationSuite.IntegrationServices.IntegrationServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="CrossDomainServiceBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="CAVES.Framework.Network.IntegrationSuite.IntegrationServices.IntegrationServiceBehavior"
        name="CAVES.Framework.Network.IntegrationSuite.IntegrationServices.IntegrationService">
        <endpoint address="" binding="basicHttpBinding" contract="CAVES.Framework.Network.IntegrationSuite.IntegrationServices.Interfaces.IIntegrationService">

        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/IntegrationService" />
          </baseAddresses>
        </host>
      </service>
      <service name="CAVES.Framework.Network.IntegrationSuite.IntegrationServices.CrossDomainService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="webHttpBinding" contract=
"CAVES.Framework.Network.IntegrationSuite.IntegrationServices.Interfaces.ICrossDomainService" behaviorConfiguration="CrossDomainServiceBehavior"/>
      </service>
    </services>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

当我使用套接字访问它时,会正确获取客户端访问策略,但当我尝试调用IntegrationService的方法时,会出现以下异常:

尝试创建时出错 对URI的请求 'http://localhost:8731/IntegrationService'. 这可能是由于试图 以跨域方式访问服务 没有适当的跨域策略 在适当的地方,或是 不适合SOAP服务。你可以 需要联系的所有者 跨域发布服务 策略文件,以确保它允许 要发送的SOAP相关HTTP头。 此错误也可能是由于使用 web服务中的内部类型 不使用 InternalsVisibleToAttribute属性。 有关详细信息,请参见内部异常 更多细节

内部异常:
{System.Security.SecurityException --->System.Security.SecurityException: 安全错误。在 System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult 异步结果)在 System.Net.Browser.BrowserHttpWebRequest.c_DisplayClass5.b_4(对象 发送状态)在 System.Net.Browser.AsyncHelper.c_DisplayClass4.b_1(对象发送状态)--内部文件结束 异常堆栈跟踪---在 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,对象状态)位于 System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult 异步结果)在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteTresponse(IAsyncResult 结果}

我的客户端访问策略文件看起来不错,应该可以正常工作,但我不确定为什么不能

<?xml version="1.0" encoding ="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from>
        <domain uri="*" />
      </allow-from>
      <grant-to>
        <socket-resource port="4502-4534" protocol="tcp" />
      </grant-to>
    </policy>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

当我使用插座访问它时, 已获取客户端访问策略 没错,但当我试着打电话给 集成服务it的方法 给我以下的例外

您的跨域策略文件只允许从端口4502到4534的套接字连接,但您的应用程序正在尝试访问端口8731。除非在浏览器外安装应用程序(具有提升的权限),否则Silverlight只能访问此端口范围,因此8731无法工作


现在,您的服务使用的是BasicHttpBinding,因此我假设您使用的是HTTP。在这种情况下,策略文件必须与服务在同一个域中提供,并且它必须位于域根(在您的情况下是)。位于的博客文章提供了有关如何为自托管服务启用SL跨域调用的更多信息。

因此,端口仅用于套接字并不重要?我认为政策是不同的。我的策略文件与根目录上的服务一起提供。但不在同一端口上。嗯。我明白了,我会检查的。我在两个web服务中都使用了端口80,现在它可以工作了。结论:始终在与服务端口相同的端口上提供clientaccesspolicy.xml(对于套接字,http上始终为80,tcp上始终为943)。