混淆动态分配WCF服务的名称

时间:2014-04-18 08:41:51

标签: c# wcf-binding

我有一台托管3个网络服务的服务器。

界面/签名将始终保持不变。

我也有adesktop应用程序。

当这个桌面应用程序将自己注册到我的服务器时,它将返回一个用于连接Web服务的IP地址。

这里的想法是我可以使用多个dedciated服务器,前50个客户端将分配服务器#1的ip地址和下一个50服务器#2等等。

为了让这个工作,我不得不在我的客户端绑定中加倍服务的名称,我想知道为什么会这样?

如果我们只专注于1个服务,这是服务器上的接口文件:

[ServiceContract]
public interface ISync
{
    [OperationContract(IsOneWay = true)]
    void UploadMotion(byte[] jpegStream, string alias, Int16 camIndex, byte[] motionLog);
}

服务器上我的web.config中的绑定是:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ThrottledBehavior">
          <serviceTimeouts transactionTimeout="0.00:00:30" />
          <serviceThrottling maxConcurrentCalls="64" maxConcurrentSessions="50" maxConcurrentInstances="1" />
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Sync" behaviorConfiguration="ThrottledBehavior">
        <endpoint address="Sync.svc" binding="basicHttpBinding" bindingConfiguration="ThrottledHttpBindingEndPoint" contract="ISync" name="wsSyncerMotion" />
      </service>
    </services>    
    <bindings>
      <basicHttpBinding>
        <binding name="ThrottledHttpBindingEndPoint" messageEncoding="Mtom" receiveTimeout="00:00:01" sendTimeout="00:00:01" transferMode="Streamed" closeTimeout="00:02:00" openTimeout="00:02:00">
          <readerQuotas maxArrayLength="32768" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

在我的Client Desktop应用程序中,我在app.config文件中有这些绑定:

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="wsSyncerMotion" messageEncoding="Mtom" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://www.a url.co.uk/Sync.svc/Sync.svc"
        binding="basicHttpBinding" bindingConfiguration="wsSyncerMotion"
        contract="wsSyncer.ISync" name="wsSyncerMotion" />
    </client>
  </system.serviceModel>

我的c#代码动态分配地址:

ChannelFactory<HomeEdition.wsSyncer.ISyncChannel> FactorySync = null;
HomeEdition.wsSyncer.ISyncChannel UpLoadSync = null;
EndpointAddress addressSync = new EndpointAddress('a new ip address' + "/sync.svc/sync.svc");
FactorySync = new ChannelFactory<HomeEdition.wsSyncer.ISyncChannel>("wsSyncerMotion", addressSync);
UpLoadSync = Shared.FactorySync.CreateChannel();
UpLoadSync.OperationTimeout = new TimeSpan(0, 0, 0, 0, 1000);

请注意:

sync.svc/sync.svc

如果我将它简化为sync.svc则不起作用。

我无法从逻辑上看到该做什么......

1 个答案:

答案 0 :(得分:3)

只需更改您的终端地址:替换

<endpoint address="Sync.svc" binding="basicHttpBinding" bindingConfiguration="ThrottledHttpBindingEndPoint" contract="ISync" name="wsSyncerMotion" />

通过

<endpoint address="" binding="basicHttpBinding" bindingConfiguration="ThrottledHttpBindingEndPoint" contract="ISync" name="wsSyncerMotion" />

  <endpoint address="http://www.a url.co.uk/Sync.svc/Sync.svc"
    binding="basicHttpBinding" bindingConfiguration="wsSyncerMotion"
    contract="wsSyncer.ISync" name="wsSyncerMotion" />

通过

  <endpoint address="http://www.a url.co.uk/Sync.svc"
    binding="basicHttpBinding" bindingConfiguration="wsSyncerMotion"
    contract="wsSyncer.ISync" name="wsSyncerMotion" />

当您希望通过多个绑定公开相同的服务时,WCF服务的基本URL的扩展非常有用。