2012-06-04 75 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」。

相關問題