ASP.NET Web Service 标准SOAP开发案例代码(自定义验证安全头SOAPHeader)
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)的更多相关文章
- 微软实战训练营(X)重点班第(1)课:SOA必备知识之ASP.NET Web Service开发实战
微软实战训练营 上海交大(A)实验班.(X)重点班 内部课程资料 链接:http://pan.baidu.com/s/1jGsTjq2 password:0wmf <微软实战训练营(X)重点班第 ...
- C# 开发XML Web Service与Java开发WebService
一.web service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量 ...
- ASP.NET Web Service如何工作(3)
ASP.NET Web Service如何工作(3) [日期:2003-06-26] 来源:CSDN 作者:sunnyzhao(翻译) [字体:大 中 小] 为了使.asmx句柄有可能反串行化SOA ...
- ASP.NET Web Service如何工作(2)
ASP.NET Web Service如何工作(2) [日期:2003-06-26] 来源:CSDN 作者:sunnyzhao(翻译) [字体:大 中 小] HTTP管道一旦调用了.asmx句柄,便 ...
- ASP.NET Web Service如何工作(1)
ASP.NET Web Service如何工作(1) [日期:2003-06-26] 来源:CSDN 作者:sunnyzhao(翻译) [字体:大 中 小] Summary ASP.NET Web ...
- 使用TcpTrace小工具截获Web Service的SOAP报文
Web Service客户端对服务端进行调用时,请求和响应都使用SOAP报文进行通讯.在开发和测试时,常常查看SOAP报文的内容,以便进行分析和调试.TcpTrace是一款比较小巧的工具,可以让我们截 ...
- ASP.NET WEB SERVICE 创建、部署与使用
PS: 开发工具 VS2010, 所有工程都为Debug状态,本人刚接触 Web Service,此文为菜鸟入门用例,高手勿笑! 转载请注明出处 :http://www.cnblogs.com/yyc ...
- 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 ...
- 【转载】在 Visual Studio 2012 中创建 ASP.Net Web Service
在 Visual Studio 2012 中创建 ASP.Net Web Service,步骤非常简单.如下: 第一步:创建一个“ASP.Net Empty Web Application”项目 创建 ...
随机推荐
- [ZJOI2005]午餐
嘟嘟嘟 贪心+dp. 首先贪心很容易想到,把吃饭时间长的人排在前面.因为打饭时间的顺序对最终答案没有影响,所以可以以吃饭时间为关键字排序. 然后就是dp了(我当时还自信满满的贪心交了一发--显然WA啊 ...
- 树莓派开启SSH
2017-04-10-raspbian-jessie默认SSH功能时关闭的 boot下新建一个ssh的空文件
- Qt warning: 构建目录必须和源文件目录为同级目录
从一台电脑转移项目到另一电脑, 路径发生变化,重新构建运行时会出现“QT 构建目录必须和源目录为同级目录”提示,解决办法很加单.如下: 方法一: 点击 project(项目)->然后,看看Bui ...
- springzuul实现限流
限流描述 https://www.cnblogs.com/LBSer/p/4083131.html 第一步添加pom文件 <!--限流--> <dependency> < ...
- DButils实现增删查改
获取数据库连接 static Connection con=JdbcUtils.MyUtils();//这个连接类静态获取要自己定义 插入 public static void insert() th ...
- Luogu4345 SHOI2015 超能粒子炮·改 Lucas、数位DP
传送门 模数小,还是个质数,Lucas没得跑 考虑Lucas的实质.设\(a = \sum\limits_{i=0}^5 a_i 2333^i\),\(b = \sum\limits_{i=0}^5 ...
- Spring Boot Admin 日志查看功能
按照官方配置POM和配置文件后,能够结合Eureka查看各微服务状态,但是日志始终查看不了,出现406等错误. 最后偶然发现,是在在从官方网站拷贝配置的时候,出现的问题. logging.file=* ...
- (原创)odoo11.0 如何运行python单元测试
官方文档中运行单元测试有三个条件 1.为模块创建tests的子包,建立测试用例 2.将配置项test_enable设置为true,命令行通过--test-enable选项 3.当模块安装或者更新时,测 ...
- windows平台快速搭建Linux(CentOS)
VMware简介 VMware Workstation(简称 “虚拟机”)是一款功能强大的桌面虚拟计算机软件,用户可在Windows平台通过VMware软件同时运行不同的操作系统.这对IT开发人员而言 ...
- 浅谈MySQL引擎(纯个人理解,如有错误请指正)
MySQL有很多引擎,MyISAM.InnoDB.MERGE.MEMORY(HEAP).BDB(BerkeleyDB).EXAMPLE.FEDERATED...等等 比较常用的就是InnoDB和MyI ...