博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.NET Web Service 标准SOAP开发案例代码(自定义验证安全头SOAPHeader)
阅读量:6257 次
发布时间:2019-06-22

本文共 3364 字,大约阅读时间需要 11 分钟。

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)
        {

       

     }

}

 

转载地址:http://qltsa.baihongyu.com/

你可能感兴趣的文章
使用eclipse创建android项目的时候为什么会生成两个项目
查看>>
常见内存错误的几点总结
查看>>
Extjs的各版本下载
查看>>
使用LVS实现负载均衡原理及安装配置详解
查看>>
hdu 3449 Consumer (依赖01背包)
查看>>
c#public、private、protected、internal、protected internal
查看>>
hdoj-5099-Comparison of Android versions
查看>>
小波变换简单介绍(2)
查看>>
Dubbo -- 系统学习 笔记 -- 示例 -- 线程模型
查看>>
Dubbo -- 系统学习 笔记 -- 示例 -- 多注册中心
查看>>
使用C++实现学生管理系统
查看>>
BroadcastReceiver类
查看>>
大杂烩 -- 查找单向链表倒数第m个元素
查看>>
SQL笔记 --- 数据库设计步骤(转)
查看>>
cocos2d-iphone 动作
查看>>
[Preact] Integrate react-router with Preact
查看>>
函数指针的说明
查看>>
Python操作redis学习系列之(集合)set,redis set详解 (六)
查看>>
Linux时间子系统之二:表示时间的单位和结构
查看>>
leetcode 221: Maximal Square
查看>>