WCF宿主与服务托管
在服务契约的操作中,DocumentList与Document则为自己定义的数据契约:
namespace BruceZhang.WCF.DocumentsExplorerDataContract注意以上定义的服务契约、服务类与数据契约的命名空间。
{
[DataContract]
public class Document
{
//DataMembers
}
}
namespace BruceZhang.WCF.DocumentsExplorerDataContract
{
[KnownType(typeof(Document))]
[CollectionDataContract]
public class DocumentList:IList<Document>
{
//IList<Document> Methods
}
}
1.自托管宿主
利用WCF提供的ServiceHost<T>提供的Open()和Close()方法,可以便于开发者在控制台应用程序,Windows应用程序乃至于ASP.NET应用程序中托管服务。不管自宿主的环境是何种应用程序,实质上托管服务的方式都是一致的。例如在控制台应用程序中:
using (ServiceHost host = new ServiceHost(typeof(DocumentsExplorerService)))
{
host.Open();
Console.WriteLine("The Service had been launched.");
Console.Read();
}
0
相关文章