我正在學習wcf和工作的示例。在此,我爲wcf服務和2個Windows應用程序託管服務和另一個客戶端appn構建了一個dll。在託管appn中,我無法在servicehost.open方法後執行代碼。我只是想知道發生了什麼事情。請幫忙。代碼後servicehost.open方法不執行
在託管APPN的代碼如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using System.ServiceModel.Description;
using WCFService;
namespace WCFServiceHost
{
public partial class Form1 : Form
{
ServiceHost sh = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Uri tcpa = new Uri("net.tcp://localhost:8000/TcpBinding");
sh = new ServiceHost(typeof(ServiceClass), tcpa);
NetTcpBinding tcpb = new NetTcpBinding();
ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior();
sh.Description.Behaviors.Add(mBehave);
sh.AddServiceEndpoint(typeof(IMetadataExchange),
MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
sh.AddServiceEndpoint(typeof(IServiceClass), tcpb, tcpa);
sh.Open();
**//This line is not executed
label1.Text = "Service Running";
//This line is not executed**
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
sh.Close();
}
}
}
一個更多的幫助:我們如何才能增加在Visual Studio服務引用2005年
爲什麼你不能執行該行?打開服務時你會得到例外嗎?它是什麼? – 2012-04-26 12:52:52
您好先生Maciej我已經複製了excepiton日誌。檢查下面的評論。 – chaitanyat 2012-04-27 09:18:18
你確定你沒有聽到8000端口上的東西嗎? – BugFinder 2012-04-27 10:19:19