1.首先要自定义SoapHeader,须继承System.Web.Services.Protocols.SoapHeader 。 using System; using System.Collections.Generic; using System.Web;/// <summary> ///自定义的SoapHeader /// </summary> public class MySoapHeader : System.Web.Services.Protocols.SoapHeader { private string userName=string.Empty; private string passWord=string.Empty; /// <summary> /// 构造函数 /// </summary> public MySoapHeader() { } /// <summary> /// 构造函数 /// </summary> /// <param name="userName">用户名</param> /// <param name="passWord">密码</param> public MySoapHeader(string userName, string passWord) { this.userName = userName; this.passWord = passWord; } /// <summary> /// 获取或设置用户用户名 /// </summary> public string UserName { get { return userName; } set { userName = value; } } /// <summary> /// 获取或设置用户密码 /// </summary> public string PassWord { get { return passWord; } set { passWord = value; } } }
2.添加WebService,并编写相应代码。 using System; using System.Collections.Generic; using System.Web; using System.Web.Services;/// <summary> ///WebService 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class WebService : System.Web.Services.WebService { //声明Soap头实例 public MySoapHeader myHeader=new MySoapHeader();
[System.Web.Services.Protocols.SoapHeader("myHeader")] [WebMethod] public string HelloWord() { //可以通过存储在数据库中的用户与密码来验证 if (myHeader.UserName.Equals("houlei")&myHeader.PassWord.Equals("houlei")) { return "调用服务成功!"; } else { return "对不起,您没有权限调用此服务!"; } } } 3.客户端调用,分别使用不设置SoapHeader与设置SoapHeader。 using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace App { class Program { static void Main(string[] args) { localhost.WebService service = new localhost.WebService(); //没有设置SoapHeader的服务调用 Console.WriteLine("没有设置SoapHeader:" + service.HelloWord()); Console.WriteLine(); //将用户名与密码存入SoapHeader; localhost.MySoapHeader header = new localhost.MySoapHeader(); header.UserName = "houlei"; header.PassWord = "houlei"; service.MySoapHeaderValue = header; //设置SoapHeader的服务调用 Console.WriteLine("设置SoapHeader:" + service.HelloWord()); Console.Read(); } } }
4.运行应用程序,查看运行结果。 1.首先要自定义SoapHeader,须继承System.Web.Services.Protocols.SoapHeader 。 using System; using System.Collections.Generic; using System.Web;/// <summary> ///自定义的SoapHeader /// </summary> public class MySoapHeader : System.Web.Services.Protocols.SoapHeader { private string userName=string.Empty; private string passWord=string.Empty; /// <summary> /// 构造函数 /// </summary> public MySoapHeader() { } /// <summary> /// 构造函数 /// </summary> /// <param name="userName">用户名</param> /// <param name="passWord">密码</param> public MySoapHeader(string userName, string passWord) { this.userName = userName; this.passWord = passWord; } /// <summary> /// 获取或设置用户用户名 /// </summary> public string UserName { get { return userName; } set { userName = value; } } /// <summary> /// 获取或设置用户密码 /// </summary> public string PassWord { get { return passWord; } set { passWord = value; } } }
2.添加WebService,并编写相应代码。 using System; using System.Collections.Generic; using System.Web; using System.Web.Services;/// <summary> ///WebService 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class WebService : System.Web.Services.WebService { //声明Soap头实例 public MySoapHeader myHeader=new MySoapHeader();
[System.Web.Services.Protocols.SoapHeader("myHeader")] [WebMethod] public string HelloWord() { //可以通过存储在数据库中的用户与密码来验证 if (myHeader.UserName.Equals("houlei")&myHeader.PassWord.Equals("houlei")) { return "调用服务成功!"; } else { return "对不起,您没有权限调用此服务!"; } } } 3.客户端调用,分别使用不设置SoapHeader与设置SoapHeader。 using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace App { class Program { static void Main(string[] args) { localhost.WebService service = new localhost.WebService(); //没有设置SoapHeader的服务调用 Console.WriteLine("没有设置SoapHeader:" + service.HelloWord()); Console.WriteLine(); //将用户名与密码存入SoapHeader; localhost.MySoapHeader header = new localhost.MySoapHeader(); header.UserName = "houlei"; header.PassWord = "houlei"; service.MySoapHeaderValue = header; //设置SoapHeader的服务调用 Console.WriteLine("设置SoapHeader:" + service.HelloWord()); Console.Read(); } } }
总之,就是再写一个java来包装头和去掉头,返回给c#使用。
http://www.cnblogs.com/houleixx/archive/2009/08/22/webservice-soapheader-security.html
生成的本地代理,比如 ServiceReference1.WebClient.SoapHeader.UserName / Password赋值即可。
也碰到过这个问题不过,后来怎么解决的,忘记了!
呵呵,对不住了,楼主!
楼主可以试试
webservice的头域认证,head里面包括如下几个字段
名称 类型 备注
sequence int 范围从0到Int的上限,然后尾追回0,周而复始。Sequence每次发送后必须自增,如果系统发现当前已发送的sequence大于请求的sequence,系统认为此媒体信息非法(只有当SP的安全认证为高时才验证sequence)
spid String 短信平台分配的SPID
timestamp String 格式yyyyMMddHHmmss(14位,24小时制),时间戳必须是当前时间的则系统认为媒体信息非法
key String 格式 sequence+spid+password+ timestamp的MD5加密字符串。这里的password也是平台分配的密钥
mode int 默认填写0
info String 暂时为空
要把这个参数传过去..
header.info = "";下一步把这个header提交,不会了
这个sms_sp.Web_SmsSP.SMSSendTask 有
感觉不应该如LZ所说的如此的复杂。
<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://webservice.sports.huawei.com" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ax21="http://webservice.sports.huawei.com/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://webservice.sports.huawei.com">
<wsdl:documentation>SMSSendTask</wsdl:documentation>
- <wsdl:types>
- <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://webservice.sports.huawei.com/xsd">
- <xs:complexType name="MediaBean">
- <xs:sequence>
<xs:element minOccurs="0" name="accepttime" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="content" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="id" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="receiverinfo" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="sendno" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
- <xs:complexType name="ExtMediaTaskBean">
- <xs:sequence>
<xs:element minOccurs="0" name="accessoryPath" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="content" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="priority" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="receiverInfo" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="sendNo" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="sendTime" nillable="true" type="xs:dateTime" />
<xs:element minOccurs="0" name="serviceId" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="spId" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="staffNo" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="subject" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
- <xs:complexType name="MediaResultBean">
- <xs:sequence>
<xs:element minOccurs="0" name="index" type="xs:int" />
<xs:element minOccurs="0" name="mediaTaskID" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="resultNo" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
- <xs:schema xmlns:ax22="http://webservice.sports.huawei.com/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://webservice.sports.huawei.com">
<xs:import namespace="http://webservice.sports.huawei.com/xsd" />
- <xs:element name="getMediasBean">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="spid" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="beginDate" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="endDate" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="getMediasBeanResponse">
- <xs:complexType>
- <xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax22:MediaBean" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="sendMediaTask">
- <xs:complexType>
- <xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="extMediaTasks" nillable="true" type="ax22:ExtMediaTaskBean" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="sendMediaTaskResponse">
- <xs:complexType>
- <xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax22:MediaResultBean" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
- <wsdl:message name="getMediasBeanRequest">
<wsdl:part name="parameters" element="ns:getMediasBean" />
</wsdl:message>
- <wsdl:message name="getMediasBeanResponse">
<wsdl:part name="parameters" element="ns:getMediasBeanResponse" />
</wsdl:message>
- <wsdl:message name="sendMediaTaskRequest">
<wsdl:part name="parameters" element="ns:sendMediaTask" />
</wsdl:message>
- <wsdl:message name="sendMediaTaskResponse">
<wsdl:part name="parameters" element="ns:sendMediaTaskResponse" />
</wsdl:message>
- <wsdl:portType name="SMSSendTaskPortType">
- <wsdl:operation name="getMediasBean">
<wsdl:input message="ns:getMediasBeanRequest" wsaw:Action="urn:getMediasBean" />
<wsdl:output message="ns:getMediasBeanResponse" wsaw:Action="urn:getMediasBeanResponse" />
</wsdl:operation>
- <wsdl:operation name="sendMediaTask">
<wsdl:input message="ns:sendMediaTaskRequest" wsaw:Action="urn:sendMediaTask" />
<wsdl:output message="ns:sendMediaTaskResponse" wsaw:Action="urn:sendMediaTaskResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="SMSSendTaskSoap11Binding" type="ns:SMSSendTaskPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <wsdl:operation name="getMediasBean">
<soap:operation soapAction="urn:getMediasBean" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="sendMediaTask">
<soap:operation soapAction="urn:sendMediaTask" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="SMSSendTaskSoap12Binding" type="ns:SMSSendTaskPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <wsdl:operation name="getMediasBean">
<soap12:operation soapAction="urn:getMediasBean" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="sendMediaTask">
<soap12:operation soapAction="urn:sendMediaTask" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="SMSSendTaskHttpBinding" type="ns:SMSSendTaskPortType">
<http:binding verb="POST" />
- <wsdl:operation name="getMediasBean">
<http:operation location="SMSSendTask/getMediasBean" />
- <wsdl:input>
<mime:content type="text/xml" part="getMediasBean" />
</wsdl:input>
- <wsdl:output>
<mime:content type="text/xml" part="getMediasBean" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="sendMediaTask">
<http:operation location="SMSSendTask/sendMediaTask" />
- <wsdl:input>
<mime:content type="text/xml" part="sendMediaTask" />
</wsdl:input>
- <wsdl:output>
<mime:content type="text/xml" part="sendMediaTask" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="SMSSendTask">
- <wsdl:port name="SMSSendTaskHttpSoap11Endpoint" binding="ns:SMSSendTaskSoap11Binding">
<soap:address location="http://134.32.32.152:9090/services/SMSSendTask.SMSSendTaskHttpSoap11Endpoint/" />
</wsdl:port>
- <wsdl:port name="SMSSendTaskHttpSoap12Endpoint" binding="ns:SMSSendTaskSoap12Binding">
<soap12:address location="http://134.32.32.152:9090/services/SMSSendTask.SMSSendTaskHttpSoap12Endpoint/" />
</wsdl:port>
- <wsdl:port name="SMSSendTaskHttpEndpoint" binding="ns:SMSSendTaskHttpBinding">
<http:address location="http://134.32.32.152:9090/services/SMSSendTask.SMSSendTaskHttpEndpoint/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
import java.util.Date;import javax.xml.namespace.QName;import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties;import com.huawei.sports.utilities.MD5Tool;
import com.huawei.sports.webservice.ExtMediaTaskBean;
import com.huawei.sports.webservice.MediaBean;
import com.huawei.sports.webservice.MediaResultBean;public class ClientTest
{
/**
* @param args
* @throws Exception
*/
public static void main11(String[] args) throws Exception
{
System.out.println(new SimpleDateFormat("MMdd").format(new Date()));
}
public static void main(String[] args) throws Exception
{
String url = "http://61.156.3.152:9090/services/SMSSendTask";
//String url = "http://localhost:9090/services/SMSSendTask";
String namespace = "http://webservice.sports.huawei.com";
String operateName = "sendMediaTask";
//String operateName = "getMediasBean";
ProxyProperties proxyProperties = new ProxyProperties();
proxyProperties.setProxyName("10.237.0.203");
proxyProperties.setProxyPort(808);
RPCServiceClient client = new RPCServiceClient();
client.addHeader(createHeaderOMElement());
/******************----***********/
//OMFactory fac = OMAbstractFactory.getOMFactory();
//QName qname = new QName(namespace, "upload");
//OMElement data = fac.createOMElement(qname);
/*****************-----***********/
//client.sendReceive(data);
Options option = client.getOptions();
EndpointReference erf = new EndpointReference(url);
option.setTo(erf);
option.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
option.setProperty(Constants.Configuration.ENABLE_MTOM,
Constants.VALUE_TRUE);
option.setTransportInProtocol(Constants.TRANSPORT_HTTP);
option.setProperty(HTTPConstants.PROXY, proxyProperties);
option.setProperty(HTTPConstants.HTTP_PROTOCOL_VERSION,
HTTPConstants.HEADER_PROTOCOL_10);
client.setOptions(option);
QName name = new QName(namespace, "sendMediaTask");
//QName name = new QName(namespace, "getMediasBean");
ExtMediaTaskBean ob1 = new ExtMediaTaskBean();
ob1.setSpId("SP1141000155183");
ob1.setSubject("SPTEST");
ob1.setSendNo("10655116114");
ob1.setReceiverInfo("13256675150");
ob1.setContent("123SDA");
ob1.setAccessoryPath("20120723183001-SP1141000155343.zip");
ob1.setSendTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2012-05-25 13:00:00"));
//ob1.setSendTime(new Date("2011-12-24"));
ExtMediaTaskBean ob2 = new ExtMediaTaskBean();
ExtMediaTaskBean[] ob = new ExtMediaTaskBean[] { ob1 };
//Object [] object = new Object[]{"SP1141000155243","2011-11-01 00:00:00","2012-05-01 00:00:00"};
Object[] object = new Object[] { ob };
//Class [] returnTypes = new Class[] { MediaBean[].class };
Class[] returnTypes = new Class[] { MediaResultBean[].class };
Object[] response = client.invokeBlocking(name, object, returnTypes);
MediaBean[] p = (MediaBean[]) response[0];
for (int i = 0; i < p.length; i++)
{
System.out.println(p[i].getContent() + "--" + p[i].getSendno());
}
}
public static OMElement createHeaderOMElement()
{
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace SecurityElementNamespace = factory.createOMNamespace("http://handler.com",
"wsse");
OMElement authenticationOM = factory.createOMElement("Authentication",
SecurityElementNamespace);
OMElement sequence = factory.createOMElement("sequence",
SecurityElementNamespace);
OMElement spid = factory.createOMElement("spid",
SecurityElementNamespace);
OMElement timestamp = factory.createOMElement("timestamp",
SecurityElementNamespace);
OMElement key = factory.createOMElement("key", SecurityElementNamespace);
sequence.setText("001");
spid.setText("SP1141000155183");
timestamp.setText("20111222010101");
key.setText(MD5Tool.generateMD5String("001" + "SP1141000155183"
+ "116114" + "20111222010101"));
authenticationOM.addChild(sequence);
authenticationOM.addChild(spid);
authenticationOM.addChild(timestamp);
authenticationOM.addChild(key);
return authenticationOM;
}
}
你要是会java,把对方给你的demo改一下,打包成命令行的jar,或者改成去掉soapheader的webservice服务,再用c#的process类去调用。
我以前遇到的一个项目就是c#调用xfire的webservice,对方也是soapheader验证,我拿着对方给的java的demo改造了一下,写了个jar程序,这个jar完成这么几个事情:
(1)接受c#的process类调用,并加soapheader包发server请求服务.
(2)从server接收返回,以标准输出方式返回给c#结果。
using System;
using System.Collections.Generic;
using System.Web;/// <summary>
///自定义的SoapHeader
/// </summary>
public class MySoapHeader : System.Web.Services.Protocols.SoapHeader
{ private string userName=string.Empty;
private string passWord=string.Empty; /// <summary>
/// 构造函数
/// </summary>
public MySoapHeader()
{ } /// <summary>
/// 构造函数
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="passWord">密码</param>
public MySoapHeader(string userName, string passWord)
{
this.userName = userName;
this.passWord = passWord;
} /// <summary>
/// 获取或设置用户用户名
/// </summary>
public string UserName
{
get { return userName; }
set { userName = value; } } /// <summary>
/// 获取或设置用户密码
/// </summary>
public string PassWord
{
get { return passWord; }
set { passWord = value; }
}
}
2.添加WebService,并编写相应代码。
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;/// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{ //声明Soap头实例
public MySoapHeader myHeader=new MySoapHeader();
[System.Web.Services.Protocols.SoapHeader("myHeader")]
[WebMethod]
public string HelloWord()
{
//可以通过存储在数据库中的用户与密码来验证
if (myHeader.UserName.Equals("houlei")&myHeader.PassWord.Equals("houlei"))
{
return "调用服务成功!";
}
else
{
return "对不起,您没有权限调用此服务!";
}
}
} 3.客户端调用,分别使用不设置SoapHeader与设置SoapHeader。 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace App
{
class Program
{
static void Main(string[] args)
{ localhost.WebService service = new localhost.WebService(); //没有设置SoapHeader的服务调用
Console.WriteLine("没有设置SoapHeader:" + service.HelloWord());
Console.WriteLine(); //将用户名与密码存入SoapHeader;
localhost.MySoapHeader header = new localhost.MySoapHeader();
header.UserName = "houlei";
header.PassWord = "houlei";
service.MySoapHeaderValue = header; //设置SoapHeader的服务调用
Console.WriteLine("设置SoapHeader:" + service.HelloWord());
Console.Read();
}
}
}
4.运行应用程序,查看运行结果。
1.首先要自定义SoapHeader,须继承System.Web.Services.Protocols.SoapHeader 。
using System;
using System.Collections.Generic;
using System.Web;/// <summary>
///自定义的SoapHeader
/// </summary>
public class MySoapHeader : System.Web.Services.Protocols.SoapHeader
{ private string userName=string.Empty;
private string passWord=string.Empty; /// <summary>
/// 构造函数
/// </summary>
public MySoapHeader()
{ } /// <summary>
/// 构造函数
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="passWord">密码</param>
public MySoapHeader(string userName, string passWord)
{
this.userName = userName;
this.passWord = passWord;
} /// <summary>
/// 获取或设置用户用户名
/// </summary>
public string UserName
{
get { return userName; }
set { userName = value; } } /// <summary>
/// 获取或设置用户密码
/// </summary>
public string PassWord
{
get { return passWord; }
set { passWord = value; }
}
}
2.添加WebService,并编写相应代码。
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;/// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{ //声明Soap头实例
public MySoapHeader myHeader=new MySoapHeader();
[System.Web.Services.Protocols.SoapHeader("myHeader")]
[WebMethod]
public string HelloWord()
{
//可以通过存储在数据库中的用户与密码来验证
if (myHeader.UserName.Equals("houlei")&myHeader.PassWord.Equals("houlei"))
{
return "调用服务成功!";
}
else
{
return "对不起,您没有权限调用此服务!";
}
}
} 3.客户端调用,分别使用不设置SoapHeader与设置SoapHeader。 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace App
{
class Program
{
static void Main(string[] args)
{ localhost.WebService service = new localhost.WebService(); //没有设置SoapHeader的服务调用
Console.WriteLine("没有设置SoapHeader:" + service.HelloWord());
Console.WriteLine(); //将用户名与密码存入SoapHeader;
localhost.MySoapHeader header = new localhost.MySoapHeader();
header.UserName = "houlei";
header.PassWord = "houlei";
service.MySoapHeaderValue = header; //设置SoapHeader的服务调用
Console.WriteLine("设置SoapHeader:" + service.HelloWord());
Console.Read();
}
}
}
4.运行应用程序,查看运行结果。