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

标签 wcf azure soa

我们的 WCF 服务遇到了 Azure 25 个内部端点的限制。为了与 SOA 原则保持一致,我们的 WCF 服务相当小,通常是系统中的每个“名词”一个。我们为每个服务契约(Contract)定义一个 Azure InternalEndpoint。我们现在想要添加第 26 个 WCF 服务,但由于 25 个端点的限制而无法添加。我们真的不想仅仅因为 Azure 的这一限制就随意开始组合服务契约(Contract)。

问题:是否有一种更好的方法来托管大量 WCF 服务,并且每个服务契约(Contract)不需要一个端点?

这是一个示例 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>

最佳答案

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

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

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

该单一端点由我们的自托管 TCP 服务应用程序中的三个不同的 netTcpBindings 使用。我们还有 TCP 服务的 Web 应用程序版本(以便在 IIS 中轻松进行本地开发托管/测试),我们使用的绑定(bind)是:

<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();
}

关于wcf - 在 Azure 中托管超过 25 个 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15748341/

相关文章:

WCF 在代码中动态设置端点和绑定(bind)

c# - IIS 中托管的 tcp 端点的 WCF 路由

c# - WCF 服务 - 请求超出限制

java - 如何将github上的java项目部署到Azure

WCF 成员资格提供程序与自定义服务授权管理器 w。自定义用户名验证器

Azure DevOps 新创建的权限组未显示在存储库安全分配中

entity-framework - Azure 应用服务上的 EF Core (1.0.0) 迁移

heroku - 在 PAAS 中部署 SOA 风格的应用程序

security - 如何保护 SOA 风格的 Symfony2 应用程序

java - SOA 中的事务