2013-04-01 42 views
2

我们正在使用WCF服务运行Azure限制的25个内部端点。根据SOA原则,我们的WCF服务相当小,通常在我们的系统中每个“名词”一个。我们正在为每个服务合同定义一个Azure InternalEndpoint。我们现在想添加我们的第26个WCF服务,但不能因为25个端点的限制。仅仅因为Azure的限制,我们真的不希望任意开始合并服务合同。在Azure中承载超过25个WCF服务

问题:是否有更好的方法来托管大量WCF服务,而不需要每个服务合同使用一个端点?

下面是一个例子csdef文件片段:

<ServiceDefinition name="MyDeployment" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"> 
    <WorkerRole name="MyWorkerRole" vmsize="Small"> 
    <Endpoints> 
     <InternalEndpoint protocol="tcp" name="IUserService" /> 
     <InternalEndpoint protocol="tcp" name="IArticleService" /> 
     <InternalEndpoint protocol="tcp" name="IDocumentService" /> 
     <InternalEndpoint protocol="tcp" name="ICommentingService" /> 
     <InternalEndpoint protocol="tcp" name="ILocationService" /> 
     <InternalEndpoint protocol="tcp" name="IAuthorizationService" /> 
     <InternalEndpoint protocol="tcp" name="IAuthenticationService" /> 
     <InternalEndpoint protocol="tcp" name="ILoggingService" /> 
     <InternalEndpoint protocol="tcp" name="IService09" /> 
     <InternalEndpoint protocol="tcp" name="IService10" /> 
     <!-- and so on --> 
     <InternalEndpoint protocol="tcp" name="IService24" /> 
     <InternalEndpoint protocol="tcp" name="IService25" /> 
     <InternalEndpoint protocol="tcp" name="IServiceWeWantToAddButCannot" /> 
    </Endpoints> 
</ServiceDefinition> 
+0

您不必为每个接口分配一个InternalEndpoint。将“InternalEndpoint”看作是防火墙(即打开的端口)的端点,而不是WCF端点。这些端点与WCF端点不同。例如,我们在单个InternalEndpoint上托管了约250个不同的TCP WCF服务。几乎将此InternalEndpoint视为映射到您的WCF绑定/行为而不是您的WCF端点。 – Jaxidian

+0

是的,将Azure端点和WCF端点视为一对一是我的问题。 – sproc

回答

0

正如我在我对你的问题的评论中提到的,我不认为你真的需要你拥有的所有这些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(); 
} 
+0

这不是说所有的契约都必须由相同的实现类(在这种情况下为endpoint.ServiceType)来实现吗?我希望能保持我的实现分离。 – sproc

+0

此外,我假设要在同一个端点上获得多个合同,对AddServiceEndpoint的调用将在嵌套循环中执行,如: 'foreach(端点中的var端点) {host} = new ServiceHost(endpoint .ServiceType,uri); foreach(var contract in endpoint.ServiceContracts) host.AddServiceEndpoint(contract,endpoint.ServiceBinging,endpoint.EndpointUrl,new Uri(endpoint.ListenUrl)); } }' – sproc

+0

我给你的代码在我们的生产中运行。这不仅仅是一个例子。他们根本不需要实现相同的接口。在我的代码中,'serviceContract'是实现的接口,对于每个服务都是不同的。 – Jaxidian

0

嗯,我会说,你推SOA“原则”有点过头了,如果最终结果是一样的东西25个服务。文件服务? ILoggingService?

有几个很好的服务不应该作为单独的实体存在,因为它们是支持你的系统的东西,但它们本身不是服务。我想说,你需要改变你的一些服务,然后结合起来,然后像10这样的东西甚至会是一个非常大的数字。

事情是这样的:

  • 支持

    • 记录
    • 文件
    • 本地化
  • 文章

  • 产品

  • 客户

    • 认证
    • 授权

类似的东西,只有4个服务。我认为你错过了构图方面。

+0

谢谢,但我认为你被我使用的化妆示例服务名称分心了。我们很满意我们的服务粒度是正确的,再一次,“我们真的不想随意开始合并服务合同”。我问是否有办法绕过25个WCF服务的限制。 – sproc

0

WCF可以托管在同几个服务physycal港口。

例如,如果您注册服务,像端点:

的http:// 145.12.12.23:1000/

那么你将无法使用同一端口。

但是如果你将添加到末尾比如合同名字 - 你能到这样的端点注册服务:

的http:// 145.12.12.23:1000/AContract

的http:// 145.12 .12.23:1000/BContract

的http:// 145.12.12.23:1000/CContract

WCF将创建代理,将地图中的每个网址到特定的主机。