本帖最后由 tys101582 于 2012-08-11 10:45:28 编辑

解决方案 »

  1.   

    就是关于C# webservice带消息头的请求写法
      

  2.   

    用WCF吧,WCF控制消息头很容易,连接webservice也没问题,而你说的c# webservice我没用过,不知道是否方便。
      

  3.   

    WEBSERVER为什么要这样设计?假如两个客户端或者以上的查询,就直接报错啊。
      

  4.   

    哈哈,终于有人遇到和我一样的问题了。我的一个项目使用c#开发,客户那里原来的厂商给他的webservice是个xfire的服务,因为对方使用的header验证,底层的东西实在搞不明白。我找了好多办法都没有办法加上header,最后一招是用java开发了一个命令行程序,用C#调用这个java命令:这个程序接收c#的输入,并包装header后向xfire发送请求并接受服务,再以标准输出返回给C#。
    总之,就是再写一个java来包装头和去掉头,返回给c#使用。
      

  5.   

    楼上真够累的,SoapHeader的相关介绍也不少,网上找找就有,比如这个:
    http://www.cnblogs.com/houleixx/archive/2009/08/22/webservice-soapheader-security.html
      

  6.   

    这个文章我看到过,不过C#学的浅看不懂呢。不过现在的处理方式也很稳定。并且因为xfire客户端会多次发送请求给服务,用java包装一下客户端只需要验证一次安全,要是用c#开发客户端,就要发送n多次安全验证。性能倒不如用java包装一下呢、
      

  7.   


    生成的本地代理,比如 ServiceReference1.WebClient.SoapHeader.UserName / Password赋值即可。
      

  8.   

    可以具体指点一下吗JustACoder??怎么写这个,本地代理类里好像没有这个吧?
      

  9.   

    以前调用朗新的web service接口时
    也碰到过这个问题不过,后来怎么解决的,忘记了!
    呵呵,对不住了,楼主!
      

  10.   

    不过记得大致的思路在消息头上增加了username 和 password 两个参数
    楼主可以试试
      

  11.   

    我这个SoapHeader点不出来,里面没这个方法呢?
      

  12.   

    信息进行安全认证:
    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 暂时为空
    要把这个参数传过去..
      

  13.   

    我现在是如何把这个头提交给这个服务呢? header.mode = 0;
                header.info = "";下一步把这个header提交,不会了
      

  14.   

    C#的引用,点web引用,引入这个webservice,系统会帮着你定义一个类的的,不需要自己写代码
      

  15.   

    我引用了,但是类里没有关于这个header的,对方是JAVA写的一个webservices
      

  16.   

    还是用我的方法吧,java写个webservices的客户端,把soapheader包装一下,用c#命令行调用就是了。我就是这么做的,超级稳定。现在java好多webservices太多框架了,搞不懂呀。
      

  17.   

    能找到这个类定义不? sms_sp.Web_SmsSP.SMSSendTask 里面有没有header属性?或者你把 wsdl 贴出来
      

  18.   


    这个sms_sp.Web_SmsSP.SMSSendTask  有
      

  19.   

    既然是webservice,那必然是符合工业标准的,也就是不需要你作什么特例编程的。
    感觉不应该如LZ所说的如此的复杂。
      

  20.   

    smsst.Header.User ? 自己点点看就知道了。或者看看 Header 的定义
      

  21.   

    smsst.Header.User 这个header是点不出来的,没有的
    <?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>
      

  22.   

    这个是他们提供的JAVA的例子,没有C#的,估计他们不会C#,没给提供。package com.webservice;import java.text.SimpleDateFormat;
    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;
        }
        
    }
     
      

  23.   

    对方,这个服务是是 java 平台实现的,MyCustomSoapHeaderValue点不出来,有高手连过C#和JAVA对接的不?
      

  24.   

    我说楼主,那些c#加soapheader的资料不是没有看过。但是我看都没有几个成功的。虽说webservice本来是标准化的,可是实现起来框架很多,各框架之间都不一定共通,更何况你还要跨语言。人家也不是不会c#,只是c#根本没有办法直接调用哪些java的webservice框架。
    你要是会java,把对方给你的demo改一下,打包成命令行的jar,或者改成去掉soapheader的webservice服务,再用c#的process类去调用。
    我以前遇到的一个项目就是c#调用xfire的webservice,对方也是soapheader验证,我拿着对方给的java的demo改造了一下,写了个jar程序,这个jar完成这么几个事情:
    (1)接受c#的process类调用,并加soapheader包发server请求服务.
    (2)从server接收返回,以标准输出方式返回给c#结果。
      

  25.   

    你用相同的框架加soapheader很容易,但是框架不同的话即便都是java写的都不容易实现调用,更何况c#.何苦为难自己呢。还是用我的方法吧。
      

  26.   

    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();
            }
        }
    }
     
    4.运行应用程序,查看运行结果。