小智 19
您可以在独立的控制台应用程序中托管它,如下所示:
using System;
using System.ServiceModel;
using Service;
namespace Host
{
class MainClass
{
public static void Main (string[] args)
{
Console.WriteLine ("WCF Host!");
var binding = new BasicHttpBinding ();
var address = new Uri ("http://localhost:8080");
var host = new ServiceHost (typeof(GreeterWcfService));
host.AddServiceEndpoint (
typeof(IGreeterWcfService), binding, address);
host.Open ();
Console.WriteLine ("Type [Enter] to stop...");
Console.ReadLine ();
host.Close ();
}
}
}
Run Code Online (Sandbox Code Playgroud)
GreeterWcfServiceWCF服务类本身在哪里,IGreeterWcfService是服务合同.
GitHub中的完整工作示例解决方案 - 包含服务,托管和客户端的单独项目.看看这个.
| 归档时间: |
|
| 查看次数: |
15397 次 |
| 最近记录: |