使用wse(Web Services Enhancements )把服务器端的文件传到客户端
来源:互联网 发布:文学气息的网名知乎 编辑:程序博客网 时间:2024/05/03 23:08
比如说,现在站点A有个附件想传给站点B,我们就可以用WSE来传。
在服务器端的webservice文件service1.asmx中写入webmethod:
这个是取附件的方法:
[WebMethod]
public void GetAttachment()
{
// 获取 SoapContext 作为响应消息
SoapContext myContext = HttpSoapContext.ResponseContext;
// 字符串,表示附件的文件名和路径。
string filePath = @"C:/My Documents/1.txt";
// 使用文件名来创建新的 DIME 附件,
// 并通过 MIME 媒体类型
// 来指定附件编码。
DimeAttachment dimeImage = new DimeAttachment(
"text/xml", TypeFormatEnum.MediaType,
filePath);
// 指定给 DIME 记录的 ID 属性。
dimeImage.Id = "1.txt";
// 将新的 DimeAttachment 对象添加到 SoapContext 对象中。
myContext.Attachments.Add(dimeImage);
}
在客户端的web站点下载附件,并写入到新的文件中:
private void DownAttachment()
{
//Service1WSE : Microsoft.Web.Services.WebServicesClientProtocol 这里的Service1继承WSE 中的类
Service1WSE sw=new Service1WSE();
//从webservice中获取附件
sw.GetAttachment();
//得到附件的流
Stream str=sw.ResponseSoapContext.Attachments[0].Stream;
int length=(int)str.Length;
byte[] attData=new byte[length];
//把附件的流写入byte中
str.Read(attData,0,length);
//创建新文件
FileInfo fi=new FileInfo(@"c:/"+sw.ResponseSoapContext.Attachments[0].Id);
FileStream fs=fi.Create();
//把byte写入新文件中
fs.Write(attData,0,length);
fs.Flush();
fs.Close();
}
注意:在webservice站点和客户端website站点的web.config中system.web节下加:
<webServices>
<soapExtensionTypes>
<add type="Microsoft.Web.Services.WebServicesExtension, Microsoft.Web.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" priority="1" group="0" />
</soapExtensionTypes>
</webServices>
- 使用wse(Web Services Enhancements )把服务器端的文件传到客户端
- 使用wse(Web Services Enhancements )把服务器端的文件传到客户端
- WSE(Web Services Enhancements)
- Web Services Enhancements (WSE) 3.0 的新功能
- 使用 Web Services Enhancements 2.0 的基于角色的安全性
- 使用 Web Services Enhancements 2.0 的基于角色的安全性
- 使用 Web Services Enhancements 发送带有附件的 SOAP 消息
- 使用 Web Services Enhancements 发送带有附件的 SOAP
- 使用 Web Services Enhancements 2.0 进行编程
- 使用 Web Services Enhancements 2.0 进行编程
- 让Visual Studio 2008 和 2010支持Web Services Enhancements (WSE) 3.0
- 如何把一个数组从客户端传到服务器端
- 使用wse实现web service的安全性
- 使用wse实现web service的安全性
- Delphi 把客户端的文件或者目录上传到服务器端
- Web Services Enhancements 管道技术内幕
- Web Services Enhancements 管道技术内幕
- Web Services Enhancements 3.0 Quick Start(二)
- .NET中文字符在页面之间传送
- 用ado.net访问sybase
- 自动登录Windows Server 2003系统 !
- 关于CodeSmith
- Linux + JDK + Tomcat + MySQL + JDBC 安装手记
- 使用wse(Web Services Enhancements )把服务器端的文件传到客户端
- (三)pygtkglExt的安装
- 选择Java接口还是抽象类
- Flash中DataGrid的使用
- 学习jpdl
- 把dataset作为一个xml文件传给客户端
- 谈软件开发工具的选择
- Tips: The vncserver cannot startup.
- 终于下定决心创建自己的blog了