WSE3.0构建Web服务安全(4):MTOM消息传输优化和文件上传、下载
The optional
mode is the default settings. In this mode the WSE processes the incoming SOAP messages whether or not they are MTOM
encoded. This gives much more flexibility to web services that are not only dealing with large amount of data. With optional the client is the one who decide whether to use MTOM
or not, if the client application request to use MTOM
the web service will use MTOM
. In always
mode all incoming and outgoing SOAP messages must be MTOM
encoded. When a SOAP request is received that is not encoded using MTOM
, an HTTP error 415: "Media unsupported" is returned to the sender. This option is ideal for Web Services that only deal with large amount of data. In never
mode all incoming SOAP messages must not be MTOM
encoded. When a SOAP request is received that is encoded using MTOM
, an HTTP error 415: "Media unsupported" is returned to the sender. That means the client application should never use MTOM
.
<mtom serverMode="optional" clientMode="On" />
</messaging>
<mtom clientMode="On" serverMode="optional" />
</messaging>
[WebService(Namespace = "http://www.cnblogs.com/frank_xl/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WSE3MTOMService : System.Web.Services.WebService
{
public WSE3MTOMService()
{
}
[WebMethod]
public byte[] DownLoadFile(string fileName)
{
byte[] file = new byte[1024];
String filePath = AppDomain.CurrentDomain.BaseDirectory + @"App_Data\" + fileName;
file = File.ReadAllBytes(filePath);
return file;
}
//上传文件,传回2进制数据
[WebMethod]
public void UpLoadFile(byte[] file)
{
String filePath = AppDomain.CurrentDomain.BaseDirectory + @"App_Data\" + "FrankXuLei.gif";
if (File.Exists(filePath))
File.Delete(filePath);
File.WriteAllBytes(filePath, file);
}
}
[WebService(Namespace = "http://www.cnblogs.com/frank_xl/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//Returns binary data secured via the ServerPolicy in the wse3policyCache.config policy file
[Policy("ServerPolicy")]
public class WSE3MTOMSecureService : System.Web.Services.WebService
{
public WSE3MTOMSecureService()
{
}
// MTOM可以使用WS-Security安全协议.
[WebMethod]
public byte[] DownLoadFileWithSecurity(string fileName)
{
byte[] file = null;
String filePath = AppDomain.CurrentDomain.BaseDirectory + @"App_Data\" + fileName;
file = File.ReadAllBytes(filePath);//从文件里读取字节流
return file;
}
}
public void DownLoadFile(String fileName)
{
//实例化服务代理类
WSE3MTOMServiceWse serviceproxy = new WSE3MTOMServiceWse();
//or alternatively set the RequireMtom property on the proxy
//serviceproxy.RequireMtom = true;
//获取文件二进制字节流
byte[] loadFile = serviceproxy.DownLoadFile(fileName);
Console.WriteLine("File Name: {0}", fileName);
Console.WriteLine("File has been downloaded without security sucessfully from Server: {0}", loadFile.Length);
//保存文件
String filePath = AppDomain.CurrentDomain.BaseDirectory + fileName;
Console.WriteLine("");
if (File.Exists(filePath))
File.Delete(filePath);
File.WriteAllBytes(filePath, loadFile);
}
//安全方式下载文件
public void DownLoadFileSecure(String fileName)
{
WSE3MTOMSecureServiceWse serviceproxy = new WSE3MTOMSecureServiceWse();
//Set anonymousForCertificateSecurity policy assertion when calling
//this secure service
serviceproxy.SetPolicy("ClientPolicy");
byte[] loadFile = serviceproxy.DownLoadFileWithSecurity(fileName);
//打印数据信息
Console.WriteLine("File Name: {0}", fileName);
Console.WriteLine("File has been downloaded with security sucessfully from Server: {0}", loadFile.Length);
//保存文件
String filePath = AppDomain.CurrentDomain.BaseDirectory + "Secure_"+ fileName;
Console.WriteLine("");
if (File.Exists(filePath))
File.Delete(filePath);
File.WriteAllBytes(filePath, loadFile);
}
//测试非加密安全上传文件
public void UpLoadFile(String fileName)
{
String filePath = AppDomain.CurrentDomain.BaseDirectory + fileName;
//实例化服务代理
WSE3MTOMServiceWse serviceproxy = new WSE3MTOMServiceWse();
//读取文件数据
byte[] upFile = File.ReadAllBytes(filePath);
//调用方法传输数据
serviceproxy.UpLoadFile(upFile);
//输出上传文件信息
Console.WriteLine("File Name: {0}", fileName);
Console.WriteLine("File has been uploaded sucessfully from Client: {0}", upFile.Length);
}
WSE3.0构建Web服务安全(4):MTOM消息传输优化和文件上传、下载相关推荐
- WSE3.0构建Web服务安全(3):WSE3.0策略配置、证书、签名、与实例开发
继WSE3.0构建Web服务安全(1):WSE3.0安全机制与实例开发和WSE3.0构建Web服务安全(2):非对称加密.公钥.密钥.证书.签名的区别和联系以及X.509 证书的获得和管理之后,今天我 ...
- 19. web 应用常用功能 -文件上传下载
文章目录 19.1 基本介绍 19.2 文件上传 19.2.1 文件上传的基本原理 19.2.2 文件上传应用实例 19.2.3 文件上传注意事项和细节 19.3 文件下载 19.3.1 文件下载的原 ...
- SpringMVC整合fastdfs-client-java实现web文件上传下载
为什么80%的码农都做不了架构师?>>> 版权声明:本文为博主原创文章,转载请标明出处(http://blog.csdn.net/wlwlwlwl015)Thanks. 目录( ...
- Java Web 文件上传下载
文章目录 1文件上传概述 1.1文件上传的作用 1.2文件上传对页面的要求 1.3 比对文件上传表单和普通文本表单的区别 1.4 对普通文本表单的测试 1.5 文件上传对Servlet的要求 2 co ...
- ftpclient读取服务器文件能获得文件名文件大小0_Spring WEB工程整合使用FTP,ftp文本文件解析入库,文件上传下载
友情提示:文章比较长,方法都是有一层层封装的,阅读需要按照文章顺序阅读 首先写一个简单的FTP工具类,先实现最基本的文件上传,下载,删除,拷贝功能.这里操作FTP是用的commons-net-3.3. ...
- SpringMVC Web实现文件上传下载功能实例解析
需求: 项目要支持大文件上传功能,经过讨论,初步将文件上传大小控制在20G内,因此自己需要在项目中进行文件上传部分的调整和配置,自己将大小都以20G来进行限制. PC端全平台支持,要求支持Window ...
- Dubbo系统里面MultipartFile文件传输问题Dubbo文件上传/传输服务
今天遇到一个问题,在Controller 层里面,直接使用MultipartFile 来接收上传的图片,遇到几个坑. 一.在spring配置文件里面配置文件上传 <!--文件上传-->&l ...
- web文件上传下载原理浅析
一.web文件上传浅析 现在有很多Web程序都有上传功能,实现上传功能的组件或框架也很多,如基于java的Commons FileUpload.还有Struts1.x和Struts2中带的上传文件功能 ...
- SpringBoot2.0 基础案例(14):基于Yml配置方式,实现文件上传逻辑
本文源码 GitHub地址:知了一笑 https://github.com/cicadasmile/spring-boot-base 一.文件上传 文件上传是项目开发中一个很常用的功能,常见的如头像上 ...
最新文章
- python中修饰器的优点和作用_Python装饰器(你想知道的这里都有)
- 就微软启动盗版系统黑屏的个人看法
- Visual Studio安装卸载模板
- 张亚勤:领导者的3种能力
- Mysql的innodb缓冲池管理(转)
- C/S+P2P网络模型(二)--上传下载文件
- CentOS中提示rz命令找不到安装lrzsz来解决
- 如何将SAP API Hub 上提供的工作流导入到 SAP BTP 上
- 二分法查找平方和_面试手撕系列:二分法
- dump java崩溃自动 不生成_基于Excel和Java自动化工作流程:发票生成器示例
- java学习(156):反序列化
- LDA(线性判别分析)详解 —— matlab
- java jdbc标签jsp_JDBC结合JSP使用(1)
- myeclipse优化方案 myeclipse 10 优化
- 分享80个贺卡图片PHP源码,总有一款适合你
- python打印列表的下标和值的例子:
- laravel 微信授权登录
- 如何解决WIN10环境下 Raid 模拟器遇到乱码问题
- 【原创】浅谈在探索数分之路上“数据思维”培养
- 支付宝/微信手机网站支付总结
热门文章
- iOS 开发 OpenGL 新手入门
- [bzoj 1954]Pku3764 The xor-longest Path
- 鲲鹏数据开源库python_google_translator介绍
- Mallet机器语言工具包-入门测试
- Cisco1242胖AP转瘦AP并加入Cisco无线控制器
- Linux 性能监测工具
- 一步一步CCNA之六:交换机vtp配置
- OPhone2.0应该重在中文应用体验
- 一个页面中多个window.onload = function(){}冲突问题解决思路
- Hadoop API编程——FileSystem操作