WEB服务器端
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public People user;
public Service () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
[SoapHeader("user")]
public string HelloWorld() {
if (user.name == "seven")
{
return "hello";
}
else
{
return "wrong";
}
}
}
public class People : SoapHeader
{
public string name;
}
客户端
添加WEB引用后
class Program
{
static void Main(string[] args)
{
localhost.Service ws = new ConsoleApplication1.localhost.Service();
ws.PeopleValue = new ConsoleApplication1.localhost.People();
ws.PeopleValue.name = "seven";
Console.WriteLine(ws.HelloWorld());
}
}