在Azure中托管超过25个WCF服务

时间:2013-04-01 17:34:15

标签: wcf azure soa

我们使用我们的WCF服务运行Azure的25个内部端点限制。为了与SOA原则保持一致,我们的WCF服务相当小,通常在我们的系统中每个“名词”一个。我们为每个服务合同定义一个Azure InternalEndpoint。我们现在想要添加我们的第26个WCF服务但不能因为25个端点的限制。我们真的不想因为Azure限制而随意开始组合服务合同。

问题:是否有更好的方法来托管许多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>

3 个答案:

答案 0 :(得分:0)

如果最终结果类似于25个服务,我会说你把SOA“原则”推得太过分了。文件服务?! ILoggingService?!

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

这样的事情:

  • 支持

    • 登录
    • 文档
    • 本地化
  • 文章

  • 产品

  • 客户

    • 验证
    • 授权

类似的东西,仅提供4项服务。我认为你错过了构图方面。

答案 1 :(得分:0)

正如我在对你的问题的评论中提到的那样,我认为你真的不需要你所拥有的所有InternalEndpoints。您正在将这些一对一与WCF端点配对。这可能是错的。相反,将它们与您的WCF绑定/行为配对(即每个端口一个,真的)。在我们的例子中,我们有大约250个不同的WCF服务都通过这个端点。以下是我们csdef文件中100%的端点:

<Endpoints>
  <InputEndpoint name="WcfConnections" protocol="tcp" port="8080" localPort="8080" />
</Endpoints>

(虽然我们使用InputEndpoint代替InternalEndpoint,但从这个问题的角度来看应该没有区别。)

我们的自托管TCP服务应用程序中有三个不同的netTcpBindings使用了这个单一端点。我们还有一个Web应用程序版本的TCP服务(用于在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>

最后,只要您愿意为每个端口共享多个服务(除了一些非常高负载情况,这应该适用于正确的自托管应用程序),那么你所做的事情是不必要的。

也许您的大问题和您需要学习的问题是,&#34;如何在自托管WCF应用中的单个端口上托管多个服务?&#34;如果是这种情况,请查看此代码(注意,我们在循环中使用的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();
}

答案 2 :(得分: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将创建将每个URL映射到特定主机的代理。