快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

bet亚洲版在线体育:WCF Service创建示例BR(一)创建WCF Service



(一)创建WCF Service

(1)创建WCF Servibet亚洲版在线体育ce类库

创建一个Class Library的项目:

删除掉落默认的Class1.cs文件,然后添加一个WCF Service项目:

Visual Studio会自动赞助你天生两个文件:HelloService.cs 和 IHelloService.cs,别的还自动添加了System.ServiceModel引用,它是WCF的核心。

改动IHelloService.cs和HelloService.cs文件。

IHelloService.cs:

namespace HelloService

{// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface namebet亚洲版在线体育 "IHelloService" in both code and config file together.

[ServiceContract]public interface IHelloService

{[OperationContract]

string GetMessage(string name);}

}

HelloService.cs:

namespace HelloService

{// NOTE: You can use the "Rename" command on the "Refactor" menu to bet亚洲版在线体育change the class name "HelloServicbet亚洲版在线体育e" in both code and config file together.

public class HelloService : IHelloService{

public string GetMessage(string name)

{return "Hello " + name;

}}

}

(2)创建WCF的Host

添加一个新的ASP.NET Empty Web Application:

添加一个新Item WCF Service

删除HelloService.svc.cs和IHelloService.cs文件。

添加HelloService Class Library的项目引用:

改动HelloService.svc为:

"C#" Debug="true" Service="HelloService.HelloService" %>

(2)支配到IIS

浏览HelloService.svc

(三)创建一个Windows Form来调用WCF Service

添加一个办事引用:

private void button1_Click(object sender, EventArgs e)

{

HelloServibet亚洲版在线体育ce.HelloServiceClient client = new HelloService.HelloServiceClient();

label1.Text = client.GetMessage(textBox1.Text);

}

您可能还会对下面的文章感兴趣: