简体   繁体   English

两个WCF服务,托管在一个控制台应用程序中

[英]Two WCF services, hosted in one console application

I have one console app as a hosting for WCF service. 我有一个控制台应用程序作为WCF服务的托管。 Now, I'm going to add another one WCf service for administer purposes. 现在,我将添加另一个WCf服务以用于管理目的。 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;
    }
}

Here is excerpt of App.config applied to services: 这是应用于服务的App.config摘录:

<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? 那是原因吗?

Thanks in advance! 提前致谢!

The issue was in wrong name of service in App.Config. 问题出在App.Config中的服务名称错误。 The right line is 右边的线是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM