【发布时间】:2011-05-13 14:25:53
【问题描述】:
我有一个托管在控制台应用程序中的 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 asyncResult) 在 System.Net.Browser.BrowserHttpWebRequest.c_DisplayClass5.b_4(Object 发送状态)在 System.Net.Browser.AsyncHelper.c_DisplayClass4.b_1(Object sendState) --- 内部结束 异常堆栈跟踪 --- 在 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback 开始方法,对象状态)在 System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(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>
【问题讨论】:
标签: silverlight wcf clientaccesspolicy.xml