正如我在我对你的问题的评论中提到的,我不认为你真的需要你拥有的所有这些InternalEndpoints
。您正在将这些与您的WCF端点进行一对一配对。这可能是错误的。相反,将它们与您的WCF绑定/行为(即每个端口一个,真的)配对。在我们的例子中,我们有大约250个不同的WCF服务都通过这个端点。这里是我们的终点的100%,从我们的csdef
文件:
<Endpoints>
<InputEndpoint name="WcfConnections" protocol="tcp" port="8080" localPort="8080" />
</Endpoints>
(虽然我们用InputEndpoint
代替InternalEndpoint
,应该是没有从这个问题的角度不同。)
即单个端点是由三个利用在我们的自托管TCP服务应用程序中不同的netTcpBindings
。我们也有我们的TCP服务Web应用程序版本(IIS中的易本地开发托管/测试),我们使用绑定是:
<bindings>
<netTcpBinding>
<binding name="A" maxBufferPoolSize="5242880" maxBufferSize="5242880" maxReceivedMessageSize="5242880" listenBacklog="100" maxConnections="1000">
<readerQuotas maxDepth="256" maxStringContentLength="16384" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
<binding name="B" maxBufferPoolSize="15728640" maxBufferSize="15728640" maxReceivedMessageSize="15728640" listenBacklog="100" maxConnections="1000">
<!-- 15MB max size -->
<readerQuotas maxDepth="256" maxStringContentLength="15728640" maxArrayLength="15728640" maxBytesPerRead="204800" maxNameTableCharCount="15728640" />
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
<binding name="C" maxBufferPoolSize="524288" maxBufferSize="524288" maxReceivedMessageSize="524288" listenBacklog="100" maxConnections="1000">
<!-- 0.5MB max size -->
<readerQuotas maxDepth="256" maxStringContentLength="524288" maxArrayLength="524288" maxBytesPerRead="204800" maxNameTableCharCount="524288" />
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</netTcpBinding>
</bindings>
最后,只要你愿意分享多每个端口的服务(除了一些非常高负载的情况下,这应该是适当的自我托管的应用程序),那么你在做什么是不必要的。
也许您的大问题和您需要学习的问题是,“如何在自行托管的WCF应用程序的单个端口上托管多个服务?”如果是这样的话,看看这个代码(注意,我们在循环使用endpoint
目标很简单,就是保存每个WCF端点的几个关键件的结构体):
// Build up Services
var hosts = new List<ServiceHost>();
foreach (var endpoint in endpoints)
{
var host = new ServiceHost(endpoint.ServiceType, new Uri(string.Format("net.tcp://{0}:{1}", FullyQualifiedHostName, SharedTcpPortNumber)));
hosts.Add(host);
foreach (var behavior in MyBehaviorSettings)
{
if (behavior is ServiceDebugBehavior)
host.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = (behavior as ServiceDebugBehavior).IncludeExceptionDetailInFaults;
else
host.Description.Behaviors.Add(behavior);
}
if (endpoint.ServiceContract == null)
throw new Exception();
if (endpoint.ServiceBinding == null)
throw new Exception();
if (endpoint.EndpointUrl == null)
throw new Exception();
if (endpoint.ListenUrl == null)
throw new Exception();
// Add the endpoint for MyService
host.AddServiceEndpoint(endpoint.ServiceContract, endpoint.ServiceBinding, endpoint.EndpointUrl, new Uri(endpoint.ListenUrl));
host.Open();
}
您不必为每个接口分配一个InternalEndpoint。将“InternalEndpoint”看作是防火墙(即打开的端口)的端点,而不是WCF端点。这些端点与WCF端点不同。例如,我们在单个InternalEndpoint上托管了约250个不同的TCP WCF服务。几乎将此InternalEndpoint视为映射到您的WCF绑定/行为而不是您的WCF端点。 – Jaxidian
是的,将Azure端点和WCF端点视为一对一是我的问题。 – sproc