using System.Xml;
using System.Xml.Serialization;
using System.Web.Services.Protocols;
using System.Configuration;
using Service.Common.Constant;

namespace Service.Common.Core.Head.Safe
{
    /// <summary>
    /// 为了安全,自定义的Soap头
    /// </summary>
    [XmlRoot("Security", Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")]
    public class Security : SoapHeader
    {
        Token _userNameTokern = new Token();

public Token UsernameToken
        {
            get { return _userNameTokern; }
            set { _userNameTokern = value; }
        }

/// <summary>
        /// 传入要正确的用户名和密码,与消息头中存储的用户名和密码,进行对比。
        /// </summary>
        /// <param name="rightUserName"></param>
        /// <param name="rightPassWord"></param>
        /// <returns></returns>
        public bool IsAuthorized(string rightUserName, string rightPassWord)
        {
            return this.UsernameToken.Username == rightUserName &&
                this.UsernameToken.Password.Value == rightPassWord;
        }

/// <summary>
        /// 公共的构造SOAP Header方法
        /// </summary>
        /// <returns></returns>
        public static Security ConstructSafeHead(string username, string passwordvalue, string passwordtype)
        {
            Security soapheader = new Security();
            soapheader.UsernameToken = new Token();
            soapheader.UsernameToken.Username = username;
            soapheader.UsernameToken.Password = new Password();
            soapheader.UsernameToken.Password.Value = passwordvalue;
            soapheader.UsernameToken.Password.Type = passwordtype;

return soapheader;
        }
    }
}

using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using Service.ESB.BaseData.Operation;
using Service.Common.Core.ESB.Request;
using Service.Common.Core.Head.Safe;
using Service.Common.Core.ESB.Response;
using Service.Common.Core.Base;
using Service.ESB.BaseData.Simulation;
using Service.Common.Log;
using Service.Common.Core.Head.Test;
using System.Xml;
using System.Xml.Serialization;
using Service.Common;
using Service.Common.Core.ESB.Base;
using Service.Common.Constant;
using Service.ESB.BaseData.Simulation.Operation;

namespace Service.ESB.BaseData
{
    /// <summary>
    /// 模拟ESB总线数据通用服务的类
    /// </summary>
    [WebService(Namespace = "http://www.iec.ch/TC57/2008/schema/message")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    [XmlRoot(Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
    public class SimulativeDataCommonService
    {
        #region 私有字段
        /// <summary>
        /// 安全头
        /// </summary>
        private Security _safeSoapHeader;

/// <summary>
        /// 测试标识头
        /// </summary>
        private TestCaseHead _testCaseHeader;
        #endregion

#region 公开的属性
        [XmlElement(Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
        public Security SafeSoapHeader
        {
            get { return _safeSoapHeader; }
            set { _safeSoapHeader = value; }
        }

public TestCaseHead TestCaseHeader
        {
            get { return _testCaseHeader; }
            set { _testCaseHeader = value; }
        }
        #endregion

#region 服务方法
        [SoapHeader("SafeSoapHeader")]//安全头
        [SoapHeader("TestCaseHeader")]//测试标识头--用于测试时标示
        [SoapDocumentMethod(RequestElementName = "RequestMessage", ResponseElementName = "ResponseMessage")]
        [WebMethod(Description = "模拟数据通用服务的接口")]
        [return: XmlElement("RequestMessage"), XmlElement("Header", typeof(HeaderClass)), XmlElement("Reply", typeof(ReplyClass))]
        [XmlInclude(typeof(RequestMessage)), XmlInclude(typeof(ResponseMessage))]
        public object[] invokeDataService(HeaderClass reqMsgHeader, RequestClass reqMsgRequest)
        {

     }

}

ASP.NET Web Service 标准SOAP开发案例代码(自定义验证安全头SOAPHeader)的更多相关文章

  1. 微软实战训练营(X)重点班第(1)课:SOA必备知识之ASP.NET Web Service开发实战

    微软实战训练营 上海交大(A)实验班.(X)重点班 内部课程资料 链接:http://pan.baidu.com/s/1jGsTjq2 password:0wmf <微软实战训练营(X)重点班第 ...

  2. C# 开发XML Web Service与Java开发WebService

    一.web service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量 ...

  3. ASP.NET Web Service如何工作(3)

    ASP.NET Web Service如何工作(3) [日期:2003-06-26] 来源:CSDN  作者:sunnyzhao(翻译) [字体:大 中 小] 为了使.asmx句柄有可能反串行化SOA ...

  4. ASP.NET Web Service如何工作(2)

    ASP.NET Web Service如何工作(2) [日期:2003-06-26] 来源:CSDN  作者:sunnyzhao(翻译) [字体:大 中 小] HTTP管道一旦调用了.asmx句柄,便 ...

  5. ASP.NET Web Service如何工作(1)

    ASP.NET Web Service如何工作(1) [日期:2003-06-26] 来源:CSDN  作者:sunnyzhao(翻译) [字体:大 中 小] Summary ASP.NET Web ...

  6. 使用TcpTrace小工具截获Web Service的SOAP报文

    Web Service客户端对服务端进行调用时,请求和响应都使用SOAP报文进行通讯.在开发和测试时,常常查看SOAP报文的内容,以便进行分析和调试.TcpTrace是一款比较小巧的工具,可以让我们截 ...

  7. ASP.NET WEB SERVICE 创建、部署与使用

    PS: 开发工具 VS2010, 所有工程都为Debug状态,本人刚接触 Web Service,此文为菜鸟入门用例,高手勿笑! 转载请注明出处 :http://www.cnblogs.com/yyc ...

  8. Web service standards: SOAP, REST, OData, and more

    Web service standards: SOAP, REST, OData, and more So far, we've covered the components of a web ser ...

  9. 【转载】在 Visual Studio 2012 中创建 ASP.Net Web Service

    在 Visual Studio 2012 中创建 ASP.Net Web Service,步骤非常简单.如下: 第一步:创建一个“ASP.Net Empty Web Application”项目 创建 ...

随机推荐

  1. javascript中apply()和call()方法及区别

    call()和apply()方法 1.方法定义 call方法: 语法:obj.call(thisObj, arg1, arg2, ...); 定义:调用一个对象的一个方法,以另一个对象替换当前对象. ...

  2. Myeclipse 启动报错 Failed to create the java Virtual Machine

    1.找到Myeclipse的安装目录 2.找到myeclipse.ini文件 3.打开myeclipse文件 你把原来的jvm.dll文件路径配置改成你的jdk安装路径中的jvm.dll路径 即: C ...

  3. 椭圆曲线签名算法的v的定义

    在之前的个个与签名相关的地方我都对v的定义感到十分困惑,知道查看了黄皮书以后才对它的作用有了一定地了解,如下: (v is the recovery id: a 1 byte value specif ...

  4. ethereum/EIPs-712 Ethereum typed structured data hashing and signing

    https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md eip title author discussions-to status ...

  5. 时间同步ctss与ntp的关系【CTSSD Runs in Observer Mode Even Though No Time Sync Software is Running (Doc ID 1054006.1) 】

    CTSSD Runs in Observer Mode Even Though No Time Sync Software is Running (Doc ID 1054006.1) In this ...

  6. oracle 查询归档增长量

    set linesize 200set pagesize 100column day format a15 heading 'Day'column d_0 format a3 heading '00' ...

  7. glVertexAttribPointer 用法简介

    在内存中采用交叉模式存储,向gpu传入顶点数据的方法  GPU: #version 100 attribute highp vec2 aPosition; attribute highp vec2 a ...

  8. Linux kernel Programming - Allocating Memory

    kmalloc #include <linux/slab.h> void *kmalloc(size_t size,int flags); void kfree(void *addr); ...

  9. Objective-C KVO深入理解

    KVO(Key Value Observing,键值观察),是Objective-C观察者模式的实现.当被观察对象的某个属性发生变化时,观察对象就会收到通知. 实现原理: 1)在运行期,为被观察对象的 ...

  10. node.js 基础三 消息推送