我有一个控制台应用程序作为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();
}
问题是常规服务工作正常(元数据交换可以提供有关服务方法的信息),而另一项服务(我在开始时提到,管理服务)根本不起作用。 这是它的原因吗?
提前致谢!
答案 0 :(得分:0)
问题在于App.Config中的服务名称错误。右边是
<service behaviorConfiguration="MyService.ServBehavior" name="MyService.ServiceAdmin">