我们制作了一个WCF应用程序,我们在On-Premise Service结构集群中托管 . 通过Service Fabric反向代理访问它给我们带来了一些困难 .

我们的集群有3个节点(例如10.0.0.1-3),应该可以通过每个节点上的反向代理(侦听端口19081)访问应用程序 . 不幸的是,它只能通过托管WCF应用程序的节点上的SF反向代理工作(也可以监听端口19081) . 通过其他节点访问它会导致400错误请求 .

如果我们在不同的端口上运行WCF服务,我们可以直接/本地访问它,但不能通过Service Fabric Reverse Proxy访问它 .

我们在群集上运行多个ASP.NET Core / REST服务,这些服务正常 .

Example

如果服务在10.0.0.1节点上运行,我们可以通过以下方式访问它:http://10.0.0.1:19081/myserviceType/soaphost/myservice.svc

但是,这些URL导致400错误的请求状态代码:http://10.0.0.2:19081/myserviceType/soaphost/myservice.svc http://10.0.0.3:19081/myserviceType/soaphost/myservice.svc

Code example

我们使用以下代码来创建WCF服务实例侦听器:

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
    return new ServiceInstanceListener[] {
        CreateWcfListener("ServiceEndpoint",  serviceProvider.GetService<ServiceType>())
    };
}

private ServiceInstanceListener CreateWcfListener<T>(string endpoint, T serviceImplementation)
{
    return new ServiceInstanceListener((context) =>
    {
        var endpointConfig = context.CodePackageActivationContext.GetEndpoint(endpoint);
        int port = endpointConfig.Port;
        string scheme = endpointConfig.Protocol.ToString();
        string host = context.NodeContext.IPAddressOrFQDN;
        string uriStem = endpointConfig.PathSuffix;
        string uri = $"{scheme}://{host}:19081{context.ServiceName.AbsolutePath}/{uriStem}";
        CustomBinding listenerBinding = CreateListenerBinding();
        WcfCommunicationListener<T> listener = new WcfCommunicationListener<T>(
            wcfServiceObject: serviceImplementation,
            serviceContext: context,
            address: new EndpointAddress(uri),
            listenerBinding: listenerBinding);
        return listener;
    }, endpoint);
}

我们想知道为什么它不起作用,但更重要的是如何解决它 .