2012-06-04 34 views
2

我的解决方案中有4个项目。 2 WCF服务库项目称为GetDetfromDB,ModifyDBService,一个控制台应用程序引用这些WCF服务库和一个Windows应用程序来调用此WCF服务。从Windows应用程序调用WCF - 主机

我在Windows应用程序中制作了控制台应用程序的参考。现在我可以从窗口应用程序调用客户端应用程序。

但现在我怎么能通过调用Windows应用程序调用在控制台应用程序中引用的服务?

注意:当我按F5或调试器 - >启动新实例时,两个服务都可以从我的控制台正确运行。我正确配置了所有绑定,端点地址。我想如何以编程方式调用它。

这里是我的控制台应用程序代码:

namespace ServiceHostConsole 
{ 
    public class Program 
    { 
     static void Main(string[] args) 
     { 
      Console.WriteLine("enter to start"); 
      Console.Read(); 

      Type serviceType = typeof(GetDetfromDB.ImpService); 
      Type serviceModifyDB = typeof(ModifyDBService.Manipulate); 

      ServiceHost host1 = new ServiceHost(serviceModifyDB); 
      host1.Open(); 

      using (ServiceHost host = new ServiceHost(serviceType)) 
      { 
       host.Open(); 

       Console.WriteLine("The Product Service is available"); 
       Console.ReadLine(); host.Close(); 
      } 

      Console.WriteLine("Please enter to close modify service"); 
      Console.Read(); 
      host1.Close(); 
     } 

     public string returnPath() 
     { 
      string folder = Environment.CurrentDirectory; 
      return folder; 
     } 
    } 
} 

从Windows应用程序,我打电话这样的....

public Form1() 
{ 
     InitializeComponent(); 

     ServiceHostConsole.Program pb = new ServiceHostConsole.Program(); 
     Process.Start(pb.returnPath()+ @"\ServiceHostConsole.exe"); 
} 

现在,当程序试图打开我收到以下错误我服务..

服务'ModifyDBService.Manipulate'具有零应用 (非基础设施cture)端点。这可能是因为没有 配置文件中发现您的应用程序,或者是因为没有匹配的服务名称 服务元素可以在 配置文件中找到,或者因为没有终点在 服务元素定义

我怀疑我只是盲目地调用这个方法而不是调用这个服务。

请帮助我摆脱这个问题,我一直在为此奋斗过去5天。

我需要发布我的Windows应用程序,当我单击安装时,我的Windows应用程序和客户端应用程序与调用服务应该打开。这是我的要求。

ServiceHostConsole我的App.config这个样子,

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <services> 
      <service name="GetDetfromDB.ImpService"> 
       <endpoint address="http://localhost:8080/MyService" binding="basicHttpBinding" 
        bindingConfiguration="" contract="GetDetfromDB.IGetExpenseValuestype" /> 
      </service> 
      <service name="ModifyDBService.Manipulate"> 
       <endpoint address="http://localhost:8081/MyService1." binding="basicHttpBinding" 
        bindingConfiguration="" contract="ModifyDBService.IManipulateDB" /> 
      </service> 
     </services> 
    </system.serviceModel> 
</configuration> 
+1

对于ServiceHostConsole应用程序,你的'app.config'是什么样的?我们需要查看''标签中的所有内容 –

回答

2

,不要引用WCF服务库。他们只能从托管服务的项目中引用。

相反,您应该使用“添加服务参考”来引用服务

请参阅“How to Consume a Web Service”。

相关问题