情况如下:我有一个内部服务器运行一些WCF服务,我希望它们可以从互联网上访问。为此,我编写了一个在面向公众的Web服务器上运行的路由服务。
此路由服务似乎有效,但是当我尝试调用方法时,我总是会收到以下错误。
由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理带有Action'http://tempuri.org/IProcessManagementService/ListProcesses'的消息。这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配。检查发件人和收件人是否具有相同的合同和相同的约束(包括安全要求,例如邮件,传输,无)。
我试图从服务中删除所有安全要求,并使用wsHTTP和basicHTTP端点。似乎没有什么可以做到的。但是,路由服务正确地传递了mex服务,因此svcutil能够构建客户端类。
我正在通过代码配置路由器。为路由服务提供服务名称列表以提供路由,以及路由器和服务器地址。
以下是路由服务的配置:
<MES.RoutingService.Properties.Settings>
<setting name="RouterAddress" serializeAs="String">
<value>http://localhost:8781/</value>
</setting>
<setting name="ServerAddress" serializeAs="String">
<value>http://10.4.1.117:8781/</value>
</setting>
<setting name="Services" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>ProcessManagementService</string>
<string>TestProcessService</string>
<string>ProcessDataEntryService</string>
<string>ProcessReportingService</string>
</ArrayOfString>
</value>
</setting>
</MES.RoutingService.Properties.Settings>
它使用以下代码调用函数,从配置文件中提供路由器地址,服务器地址和服务名称。
var routers = new List<ServiceHost>();
foreach (var service in _services)
{
var routerType = typeof(IRequestReplyRouter);
var routerContract = ContractDescription.GetContract(routerType);
var serviceHost = new ServiceHost(typeof (System.ServiceModel.Routing.RoutingService));
var serverEndpoints = new List<ServiceEndpoint>();
//Configure Mex endpoints
serviceHost.AddServiceEndpoint(routerType, MetadataExchangeBindings.CreateMexHttpBinding(), _routerAddress + service + "/mex");
serverEndpoints.Add(new ServiceEndpoint(routerContract, MetadataExchangeBindings.CreateMexHttpBinding(), new EndpointAddress(_serverAddress + service + "/mex")));
//RAR SECURITY SMASH.
var binding = new WSHttpBinding(SecurityMode.None);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Message.EstablishSecurityContext = false;
binding.Security.Message.NegotiateServiceCredential = false;
binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
//Configure WsHttp endpoints
serviceHost.AddServiceEndpoint(routerType, binding, _routerAddress + service);
serverEndpoints.Add(new ServiceEndpoint(routerContract, binding, new EndpointAddress(_serverAddress + service)));
var basicBinding = new BasicHttpBinding();
serviceHost.AddServiceEndpoint(routerType, basicBinding, _routerAddress + service + "/basic");
serverEndpoints.Add(new ServiceEndpoint(routerContract, basicBinding, new EndpointAddress(_serverAddress + service + "/basic")));
//Set Routing Tables
var configuration = new RoutingConfiguration();
configuration.FilterTable.Add(new MatchAllMessageFilter(), serverEndpoints);
serviceHost.Description.Behaviors.Add(new RoutingBehavior(configuration));
routers.Add(serviceHost);
}
return routers;
服务在启动时调用此函数,然后打开路由器列表中返回的每个服务主机。
服务器本身通过以下app.config配置
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="noSecurityBinding">
<security mode="None">
<transport clientCredentialType="None" />
<message establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="MES.ProcessManagerServiceLibrary.ProcessManagementService">
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint binding="wsHttpBinding" bindingConfiguration="noSecurityBinding"
contract="MES.ProcessManagerServiceLibrary.IProcessManagementService" />
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
contract="MES.ProcessManagerServiceLibrary.IProcessManagementService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8781/ProcessManagementService/" />
</baseAddresses>
</host>
</service>
<service name="MES.ProcessManagerServiceLibrary.TestProcessService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="noSecurityBinding"
contract="MES.ProcessManagerServiceLibrary.ITestProcessService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
contract="MES.ProcessManagerServiceLibrary.ITestProcessService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8781/TestProcessService/" />
</baseAddresses>
</host>
</service>
<service name="MES.ProcessManagerServiceLibrary.ProcessDataEntryService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="noSecurityBinding"
contract="MES.ProcessManagerServiceLibrary.IProcessDataEntryService" />
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
contract="MES.ProcessManagerServiceLibrary.IProcessDataEntryService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8781/ProcessDataEntryService/" />
</baseAddresses>
</host>
</service>
<service name="MES.ProcessManagerServiceLibrary.ProcessReportingService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="noSecurityBinding"
contract="MES.ProcessManagerServiceLibrary.IProcessReportingService" />
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
contract="MES.ProcessManagerServiceLibrary.IProcessReportingService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8781/ProcessReportingService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我错过了什么?
编辑:我想我发现了问题 - 路由服务正在为服务返回此配置 -
<client>
<endpoint address="http://shco-appsrv1.us.shepherd.ad:8781/ProcessManagementService/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IProcessManagementService"
contract="IProcessManagementService" name="WSHttpBinding_IProcessManagementService" />
<endpoint address="http://shco-appsrv1.us.shepherd.ad:8781/ProcessManagementService/basic"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProcessManagementService"
contract="IProcessManagementService" name="BasicHttpBinding_IProcessManagementService" />
</client>
这指向内部服务器,而不是外部服务器。不知道这是否是路由服务的标准行为,或者它是否是可覆盖的行为。
答案 0 :(得分:4)
好像你没有正确连接配置中的serviceModel客户端元素。需要像处理标准WCF服务一样配置RoutingService,并将“拦截”端点暴露给路由服务。然后,它使用客户端元素端点重定向服务调用。
下面是一个不依赖代码的简单配置。它包含各种路由值的命名约定,可以保持一切正常。您可以将配置中的“YourRoutedService”字符串替换为您的实际服务名称,但应保留后缀以保持所有连接正确。
我首先要获得一个基于文件的配置,成功地进行端到端调用(使用这种方法进行调整时不需要重新编译)。接下来,将您的代码基于文件配置,并删除正在配置代码的元素。
<system.serviceModel>
<services
name="System.ServiceModel.Routing.RoutingService"
behaviorConfiguration="RoutingBehavior" >
<endpoint
name="RouterEndpoint"
address=""
binding="wsHttpBinding"
bindingConfiguration="Http"
contract="System.ServiceModel.Routing.IRequestReplyRouter" />
<!-- List all endpoints to be routed via EndpointName routing filter -->
<endpoint
name="YourRoutedServiceName"
address="YourRoutedService"
contract="System.ServiceModel.Routing.IRequestReplyRouter"
binding="wsHttpBinding"
bindingConfiguration="Http" />
</services>
<routing>
<filters>
<!-- Active filters -->
<filter
name="YourRoutedServiceFilter"
filterType="EndpointName"
filterData="YourRoutedServiceName" />
</filters>
<filterTables>
<filterTable name="WebLayer">
<!-- Map to client Endpoints-->
<add
filterName="YourRoutedServiceFilter"
endpointName="YourRoutedServiceNameEndpoint"
priority="0" />
</filterTable>
</filterTables>
</routing>
<behavior name="RoutingBehavior">
<routing routeOnHeadersOnly="false" filterTableName="WebLayer" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpsGetEnabled="true" />
</behavior>
<bindings>
<wsHttpBinding>
<binding name="Http">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint
name="YourRoutedServiceNameEndpoint"
address="http://somehost/YourRoutedService/Service.svc"
contract="*"
binding="wsHttpBinding"
bindingConfiguration="Http" />
</client>
</system.serviceModel>