两个WCF服务,托管在一个控制台应用程序中
本文关键字:一个 控制台 应用程序 服务 WCF 两个 | 更新日期: 2023-09-27 18:23:36
我有一个控制台应用程序作为WCF服务的宿主。现在,我将添加另一个WCf服务用于管理目的。所以,这是我的代码:
[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
应用于服务的摘录:
<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>
以下是我如何启动服务:
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();
}
问题是,常规服务运行良好(元数据交换可以提供有关服务方法的信息),而另一个服务(我在开头提到,管理服务)根本不起作用。这就是原因吗?
提前感谢!
问题出现在App.Config中错误的服务名称中。右行是
<service behaviorConfiguration="MyService.ServBehavior" name="MyService.ServiceAdmin">