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. C# Repeater、webdiyer:AspNetPager分页 AspNetPager分页样式

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/vaecnfeilong/article/details/32712611 AspNetPager分页 ...

  2. Problem UVA1572-Self-Assembly(拓扑排序)

    Problem UVA1572-Self-Assembly Accept: 196  Submit: 1152 Time Limit: 3000 mSec Problem Description Au ...

  3. Usaco 2019 Jan Platinum

    Usaco 2019 Jan Platinum 要不是昨天老师给我们考了这套题,我都不知道usaco还有铂金这么一级. 插播一则新闻:杨神坚持认为铂金比黄金简单,原因竟是:铜 汞 银 铂 金(金属活动 ...

  4. metamask源码学习-inpage.js

    The most confusing part about porting MetaMask to a new platform is the way we provide the Web3 API ...

  5. PAT A1149 Dangerous Goods Packaging (25 分)——set查找

    When shipping goods with containers, we have to be careful not to pack some incompatible goods into ...

  6. AI 蒙特卡罗算法

    蒙特卡罗算法,是一类随机算法,用于求近似解. 1.Las Vegas(拉斯维加斯)算法和蒙特卡罗算法 两者都是随机算法. 前者:要么正确解,要么错误解.采样越多,越有可能得到正确解. 后者:近似解.采 ...

  7. AI 循环神经网络(RNN)

    循环神经网络(Recurrent Neural Network,简称RNN),通常用于处理序列数据.正如卷积神经网络通常用于处理网格数据(例如图像)一样. 1.展开计算图 输入.输出.记忆 权值 2. ...

  8. linux编程头文件所在路径的问题

    一.问题引入 1.头文件与库 当我们在PC主机linux环境下(如ubuntu),编写linux应用程序,然后利用gcc来编译.在源代码的开始位置会写入头文件,那是因为我们使用了系统提供的库函数,例如 ...

  9. Vue-Vue列表渲染v-for

    v-for 指令需要以 site in sites 形式的特殊语法 一.v-for 循环数组 HTML代码 <div id="app"> <ul> < ...

  10. Rabbitmq-direct演示

    在上一节中我们创建了一个日志系统.实现将日志消息广播给所有的cusumer. 在这片教程中,我们将为日志系统添加一个功能:仅仅订阅一部分消息.比如:我们可以直接将关键的错误类型日志消息保存到日志文件中 ...