1

安装程序是 raspberry pi 上的 mono 最新稳定版,使用 .NET 4.5 从服务器上的服务轮询数据。

我的服务器端配置:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="vlcBehaviour">
          <serviceMetadata  httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <services>
      <service name="ser.Serwys">
        <endpoint address="net.tcp://192.168.56.1:9070/WindowService" binding="netTcpBinding" bindingConfiguration="AnonymousTcpBinding"
                  contract="Window.Service.IWindowServiceHost" />
      </service>
    </services>

    <bindings>
      <netTcpBinding>
        <binding name="AnonymousTcpBinding" receiveTimeout="00:00:01"
                 sendTimeout="00:00:01"
                 maxBufferSize="1000"
                 maxConnections="100"
                 maxBufferPoolSize="100"
                 listenBacklog="200"
                 maxReceivedMessageSize="1000">
          <security mode="None" />
        </binding>
      </netTcpBinding>
    </bindings>
  </system.serviceModel>

在客户端:

<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="maxItems">
                <dataContractSerializer maxItemsInObjectGraph="2147483646" />
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <bindings>
        <netTcpBinding>
            <binding name="AnonymousTcpBinding" openTimeout="00:00:01" receiveTimeout="00:00:01" sendTimeout="00:00:01" maxBufferSize="1000" maxConnections="200" listenBacklog="200" maxReceivedMessageSize="1000">
                <security mode="None" />
            </binding>
        </netTcpBinding>
    </bindings>
    <client>
        <endpoint name="WindowService" address="net.tcp://192.168.56.1:9070/WindowService" binding="netTcpBinding" bindingConfiguration="AnonymousTcpBinding" contract="Window.Service.IWindowServiceHost" />
    </client>
</system.serviceModel>

服务合同:

namespace Window.Service
{
    [ServiceContract(
        Namespace = "http://window",
        Name = "WindowHost")]
    public interface IWindowServiceHost
    {
        [OperationContract]
        void Connect(int windowId);

        [OperationContract]
        void Disconnect();

        [OperationContract]
        DisplayData GetData();
    }
}

服务实施:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
    public class Serwys:IWindowServiceHost

被调用的方法:

    public DisplayData GetData()
    {
        Console.WriteLine("Called get data {0}:{1}:{2}",DateTime.Now.Minute,DateTime.Now.Second,DateTime.Now.Millisecond);
        return new DisplayData
        {
            BoxesInProgress = 1,
        };
    }

从客户端调用 GetData 需要越来越多的时间,不知道为什么。我也在 Ubuntu 上对其进行了测试,Mono 是我如何记录它的最新版本:

Stopwatch stp = new Stopwatch();
stp.Start();
var data = remote.GetData();
stp.Stop();
log.WarnFormat("Polling service took: {0} ms", stp.ElapsedMilliseconds);

有什么解释吗??我认为这是 Mono 错误,因为设置非常基本,没有调用并发方法非常简单,而且轮询时间正在增加。

我在计时器经过时调用它,对于测试,我每 10 毫秒调用一次,但即使我每秒调用一次,它也在增长,但速度较慢,这只会在所有崩溃之前给我更多时间。

4

0 回答 0