两个WCF服务,托管在一个控制台应用程序中 [英] Two WCF services, hosted in one console application

查看:57
本文介绍了两个WCF服务,托管在一个控制台应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制台应用程序作为WCF服务的托管.现在,我将添加另一个WCf服务以用于管理目的.所以,这是我的代码:

I have one console app as a hosting for WCF service. Now, I'm going to add another one WCf service for administer purposes. So, here is my code:

[ServiceContract]
public interface IServiceAdmin
{
    [OperationContract]
    int GetCount();
}

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
public class ServiceAdmin : IServiceAdmin
{        
    public int GetCount()
    {
        // It's just a stub to go on
        return 1;
    }
}

以下是App.config应用于服务的摘录:

Here is excerpt of App.config applied to services:

<serviceBehaviors>
     <behavior name="MyService.ServBehavior">
       <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
       <serviceMetadata httpGetEnabled="false" />
       <serviceDebug includeExceptionDetailInFaults="true" />
     </behavior>
   </serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MyService.ServBehavior" name="MyService.MyServ">
  <endpoint address="MyServ" behaviorConfiguration="" binding="netTcpBinding" contract="MyService.IMyServ"  isSystemEndpoint="false" />
  <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="MyService.ServBehavior" name="MyService.MyServAdmin">
  <endpoint address="MyServ" behaviorConfiguration="" binding="netTcpBinding" contract="MyService.IServiceAdmin"  isSystemEndpoint="false" />
  <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />  
</service>

这是我如何启动服务的方法:

And here is how I get services started:

static void Main(string[] args)
{
ServiceHost myserviceHost = new ServiceHost(typeof(MyServ), new Uri("net.tcp://192.168.1.40:8730/"));
myserviceHost.Open();

ServiceHost myAdminHost = new ServiceHost(typeof(AServiceAdmin), new Uri("net.tcp://192.168.1.40:31337/");
myAdminHost.Open();

Console.ReadLine();
}

问题在于常规服务运行良好(元数据交换可以提供有关服务方法的信息),而另一项服务(我在开始时提到的管理服务)根本无法正常工作. 那是原因吗?

The issue is that regular service working good (metadata exchanging can provide info on service methods) and another service (which I mentioned at the beginning, administer service) is not working at all. That is the reason of it?

提前谢谢!

推荐答案

问题出在App.Config中服务名称错误.右边的线是

The issue was in wrong name of service in App.Config. The right line is

<service behaviorConfiguration="MyService.ServBehavior" name="MyService.ServiceAdmin">

这篇关于两个WCF服务,托管在一个控制台应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆