我有一个托管在控制台应用程序中的 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 sendState) 在 System.Net.Browser.AsyncHelper.<>c_ DisplayClass4.b _1 (Object sendState) --- 内部异常堆栈跟踪的结束 --- 在 System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) 在 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>