情况如下:我有一个内部服务器运行一些 WCF 服务,我希望它们可以从整个 Internet 访问。为此,我编写了一个在我们面向公众的 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>
这指向内部服务器,而不是外部服务器。不知道这是否是路由服务的标准行为,或者它是否是可覆盖的行为。