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”项目 创建 ...
随机推荐
- js常见错误类型
(1)SyntaxError SyntaxError是解析代码时发生的语法错误 // 变量名错误 var 1a; // 缺少括号 console.log 'hello'); (2)ReferenceE ...
- MySQL性能分析工具之PROFILE
Mysql Profile 如何开启Profiles功能以及如何简单使用: https://www.cnblogs.com/zengkefu/p/6519010.html MySQL profiles ...
- 恶意软件的bypass
导读 在网络安全的背景下,尽管存在反恶意软件控制,但逃避是执行恶意代码的做法.这种策略不会利用可修复的缺陷.相反,他们利用阻止现实世界中恶意软件检测的因素来实现其完整的理论潜力. 恶意软件这些逃避因素 ...
- vue指令相关的
阅读目录 1.v-text 2.v-html 3.v-show 4.v-if 5.v-if vs v-show 6.v-else 7.v-for 8.v-on 9.v-bind 和 v-model 1 ...
- Java 中数组的内存分配
Java 中数组的内存分配 1.Java 程序在运行时,需要在内存中分配空间.为了提高运算效率,就对空间进行了不同区域的划分,因为每一片区域都有特定的处理数据和内存管理方式. 2.数组基本概念 数组是 ...
- java static 在java 中的使用。
static表示“全局”或者“静态”的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念. 被static修饰的成员变量和成员方法独立于该类的任何 ...
- 学习CSS布局 - 盒模型
盒模型 在我们讨论宽度的时候,我们应该讲下与它相关的另外一个重点知识:盒模型. 当你设置了元素的宽度,实际展现的元素却超出你的设置: 这是因为元素的边框和内边距会撑开元素. 看下面的例子,两个相同宽度 ...
- arp绑定IP
0.拓扑图 1. 现象:for i in `seq 1 20` ;do sleep 1|telnet www.baidu.com 80 ;done 速度有很明显的卡顿 2.操作:用tcpdump ...
- Emacs 番茄钟 pomidor
Windows 10 pomidor:https://github.com/TatriX/pomidor alert :https://github.com/jwiegley/alert toaste ...
- STM32 printf()函数和scanf()函数重定向到串口
STM32 printf()函数和scanf()函数重定向到串口 printf()函数和scanf()函数重定向 在学习STM32的时候,常常需要用串口来测试代码的正确与否,这时候就要要用到print ...