1、新建一个类,如"AuthHeaderUser",继承于"System.Web.Services.Protocols.SoapHeader"类

2、新建WebService,有一个AuthHeaderUser类型的属性

3、新建WebService的一个Web方法,指定Soap头信息,如:
[SoapHeader("AuthenticationUser")]
[WebMethod(Description="返回股票行情信息")]
public DataSet GetQuotedPrice()
{
if (AuthenticationUser != null) //step4,验证Soap头是否为空
{
//验证
WebServiceSoapHeaderAuthentication.DAL.LoginResult lr =
new WebServiceSoapHeaderAuthentication.DAL.UserDAL().Login(AuthenticationUser.UserId, AuthenticationUser.Password);
if (lr == LoginResult.Succeed)//登录成功
return new WebServiceSoapHeaderAuthentication.DAL.QuotedPriceDAL().GetQuotedPriceDataset();
else
throw new ApplicationException("Log in failed : " + lr.ToString());
}
else
throw new SoapHeaderException("......", SoapException.ClientFaultCode);
}

4、client引用:
//Web服务
localhost1583QuotedPriceService.QuotedPriceService service =
new WebServiceSoapHeaderAuthentication.QuotedPriceViewForm.localhost1583QuotedPriceService.QuotedPriceService();

//准备Soap头
WebServiceSoapHeaderAuthentication.BOL.User u = CurrentUser.getInstance();
localhost1583QuotedPriceService.AuthHeaderUser login_user =
new WebServiceSoapHeaderAuthentication.QuotedPriceViewForm.localhost1583QuotedPriceService.AuthHeaderUser();
login_user.UserId = u.UserId;
login_user.Password = u.UserPassword;

//Soap头赋值
service.AuthHeaderUserValue = login_user;

DataSet ds = service.GetQuotedPrice();
//todo:......

5、完毕

WebService之Soap头验证入门的更多相关文章

  1. WebService它Soap头验证进入

    1.创建一个新的类.如"AuthHeaderUser",在传承"System.Web.Services.Protocols.SoapHeader"类别 2.新W ...

  2. Delphi在调WebService的时候加Soap头验证

    procedure   ws: WebServiceSoap;   H: XXXHeader; begin   ws := GetWebServiceSoap;   H := XXXHeader.Cr ...

  3. Postman调用WebService,包括头验证部分

    Postman调用WebService时,Body中选择Raw,最右端选择XML(txt/xml),然后把某个方法显示在页面的xml拷贝到请求框中即可,如下图: 以下是postman中的设置,

  4. 动态调用Webservice 支持Soapheader身份验证(转)

    封装的WebserviceHelp类: using System; using System.CodeDom; using System.CodeDom.Compiler; using System. ...

  5. 构建安全的Xml Web Service系列之初探使用Soap头

    原文:构建安全的Xml Web Service系列之初探使用Soap头 Xml Web Service 从诞生那天就说自己都么都么好,还津津乐道的说internet也会因此而进入一个新纪元,可5年多来 ...

  6. WebService之SOAP

    SOAP(Simple Object Access Protocol),它是一种标准消息传递协议,通常是Web Service的事实标准.SOAP是以XML为基础,SOAP消息格式是由XML Sche ...

  7. 重温WCF之发送和接收SOAP头(三)

    SOAP头可以理解为一种附加信息,就是附加到消息正文的内容. 既然消息头是附加信息,那有啥用呢?你可别说,有时候还真有不少用处.举个例子,WCF的身份验证是不是很麻烦?还要颁发什么证书的(当然不是荣誉 ...

  8. 传说中的WCF(4):发送和接收SOAP头

    如果你实在不明白Header是个啥玩意儿,你就想一想你发送电子邮件时,是不是有个叫“附件”的东东?对啊,那么SOAP头是不是可以理解为一种附加信息?就是附加到消息正文的内容. 消息正文又是啥?WCF除 ...

  9. WebService的几种验证方式

    转 http://www.cnblogs.com/yoshiki1895/archive/2009/06/03/1495440.html WebService的几种验证方式 1.1      WebS ...

随机推荐

  1. 为什么java源文件中只允许一个public类存在

    1.提出问题 为什么java源文件中只允许一个public类存在? 2.分析问题 问题涉及到的条件:源文件的名字    public类     main方法 一般我们在编写一个源文件的时候: 一个pu ...

  2. Linux下使用Mysql

    一.连接MySQL数据库 一个最简单的程序示例: #include <stdio.h> #include "mysql.h" int main() { MYSQL my ...

  3. java输出空心菱形

    package com.zsh; import java.util.Scanner; public class Test08 { public static void main(String[] ar ...

  4. springboot 开发入门,及问题汇总

    1 . springboot简单介绍(http://projects.spring.io/spring-boot/) 现在的web项目几乎都会用到spring框架,而要使用spring难免需要配置大量 ...

  5. 源代码编译lamp环境

    没有办法用 rpm查询一个源代码包是否安装 因为 并不是用rpm安装的 可以先吧 selinux 给禁用掉  iptables -F 把防火墙规则全部删除 首先确保 gcc  gcc-c++   ma ...

  6. Disqus – About Disqus

    Disqus – About Disqus   Disqus is a free service that enables great online communities. As the web's ...

  7. 生产者、消费者 C源码,gcc编译通过

    /*生产者.消费者*/ #include<stdio.h> #include<pthread.h> #define BUFFER_SIZE 16 /***struct prod ...

  8. MySQL学习笔记之中的一个 MySQL入门

    本人之前接触的关系型数据库主要是oracle和sqlserver,而对于mysql知之甚少,但查阅网上资料发现,mysql与oracle非常相似,所以学起来应该不会非常费劲,在总结的时候可能很多其它的 ...

  9. Python heapq 模块的实现 - A Geek's Page

    Python heapq 模块的实现 - A Geek's Page Python heapq 模块的实现

  10. [Erlang危机](5.0)执行时指标

    原创文章.转载请注明出处:server非业余研究http://blog.csdn.net/erlib 作者Sunface .  Then, in times of need, it's also po ...