几秒钟后,WCF客户端始终出现故障

时间:2016-03-07 14:05:08

标签: c# wcf app-config endpoint servicehost

我有一个适用于app.config文件的WCF服务。我决定将这个app.config内容移动到代码中,这样我就可以更好地控制了。我尝试了以下方法:

string localIP = GetLocalIP();

int PrimaryPort = 9900;
Uri PrimaryUri = new Uri(String.Format("net.tcp://{0}:{1}/", localIP, PrimaryPort));

int MetaPort = 9901;
Uri MetaUri = new Uri(String.Format("http://{0}:{1}/", localIP, MetaPort));

AES_MarketDataService aes = new AES_MarketDataService();

using (ServiceHost aesHost = new ServiceHost(aes, MetaUri, PrimaryUri))
{
    NetTcpBinding PrimaryBinding = new NetTcpBinding();
    PrimaryBinding.Name = "AES";
    PrimaryBinding.ReceiveTimeout = new TimeSpan(0, 0, 10);
    PrimaryBinding.Security.Mode = SecurityMode.Transport;
    PrimaryBinding.ReliableSession.Enabled = true;

    ServiceMetadataBehavior mexBehavior = new ServiceMetadataBehavior();
    mexBehavior.HttpGetEnabled = true;

    aesHost.Description.Behaviors.Add(mexBehavior);
    aesHost.AddServiceEndpoint(typeof(IAES_MarketDataService), PrimaryBinding, "AES");
    aesHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

    aesHost.Open();

    Console.WriteLine("Host started at {0}: svc={1}, meta={2}", DateTime.Now, PrimaryUri.AbsoluteUri, MetaUri.AbsoluteUri);

    Console.ReadLine();
}

这样可行,但由于某种原因,客户端在第一次调用服务后几秒钟就会出现故障。服务器端没有例外,如果我重新启动客户端,我完全能够再次拨打电话(几秒钟后客户端再次出现故障)。

缺少app.config文件的代码是什么?

0 个答案:

没有答案