我試圖將以前在任務欄中的.asmx服務中運行的WCF服務封裝到控制檯應用程序中。在ServiceHost(控制檯應用程序)中運行的WCF服務
這裏是結束了WCF服務的代碼:
class Program
{
static void Main(string[] args)
{
Uri uri = new Uri("http://localhost:5000");
using (ServiceHost host = new ServiceHost(typeof(CheckoutService), uri))
{
Console.WriteLine("Prepping CheckoutService server");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.Open();
Console.Clear();
Console.WriteLine("CheckoutService server up and running");
Console.WriteLine("Press Return to stop service at any point");
Console.ReadLine();
host.Close();
}
}
然而,應該接收該服務(其使用的服務被包裹成一個控制檯應用程序之前上班)客戶端應用程序正在崩潰出與錯誤:
There was no endpoint listening at http://localhost:5000/CheckoutService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
此客戶端的app.config端點配置爲:
<endpoint
address="http://localhost:5000/CheckoutService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICheckoutService"
contract="CheckoutServiceServer.ICheckoutService" name="BasicHttpBinding_ICheckoutService" />
我想也許我在託管WCF服務的控制檯項目中缺少某種形式的.config
文件,但我可能是錯的!
討厭上尉明顯,但聽起來好像服務沒有運行。 – JayC
你打開主機,清除控制檯,然後你馬上再次關閉主機......如果你馬上再次關閉主機,服務應該如何啓動和運行? –
是的,我錯過了Console.ReadLine(),它是爲了保持它打開,但添加後,我仍然得到同樣的問題。 – Moza