Lightswitch文件上传(WCF版)
来源:互联网 发布:java extends 源码 编辑:程序博客网 时间:2024/06/07 23:22
思路:
1、建立server端的上传模块
2、建立WCF服务接口
3、配置web.config文件
4、建立client端的脚本
一、建立server端的上传过程(废话不多说,直接上代码)
Imports System.Net.WebClientImports System.IOImports System.NetPublic Module ftpHelper Private ReadOnly SMTPuserid As String = "登录名" Private ReadOnly SMTPpassword As String = "登录密码" Public Sub FtpUpload(ByVal filename As String, ByVal byt() As Byte) Dim fwc As New WebClient fwc.Credentials = New NetworkCredential(SMTPuserid, SMTPpassword) Dim add As String = "ftp://bxu2359560474.my3w.com/myfolder/" + filename fwc.UploadData(add, byt) End SubEnd Module
二、建立WCF服务接口
选择server点右键->添加->新建项->web->WCF服务,输入名称FtpService,此时会建立两个文件(FtpService,IFtpService)。
Imports System.ServiceModelImports System.ServiceModel.Activation' 注意: 使用上下文菜单上的“重命名”命令可以同时更改代码、svc 和配置文件中的类名“FtpService”。' 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 FtpService.svc 或 FtpService.svc.vb,然后开始调试。Namespace LightSwitchApplication <AspNetCompatibilityRequirements( RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> Public Class FtpService Implements IFtpService Public Function FtpUpload(filename As String, byt() As Byte) As Boolean Implements IFtpService.ftpUp Try ftpHelper.FtpUpload(filename, byt) Catch ex As Exception Return False End Try Return True End Function End ClassEnd Namespace
Imports System.ServiceModelImports System.ServiceModel.Web' 注意: 使用上下文菜单上的“重命名”命令可以同时更改代码和配置文件中的接口名“IFtpService”。<ServiceContract()>Public Interface IFtpService <OperationContract()><WebInvoke(Method:="POST", BodyStyle:=WebMessageBodyStyle.Wrapped, ResponseFormat:=WebMessageFormat.Xml)> Function ftpUp(filename As String, byt() As Byte) As BooleanEnd Interface
看对应代码就知道是对应哪个文件了。
三、配置web.config文件
打开web.config,找到<system.serviceModel>,拉到最后就能找到
<system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <behaviors> <!-- 服务行为 --> <serviceBehaviors> <behavior> <dataContractSerializer maxItemsInObjectGraph="6553600" /> <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <webHttpBinding> <binding maxReceivedMessageSize="6553600" /> </webHttpBinding> <basicHttpBinding> <binding name="FtpServiceBinging" maxReceivedMessageSize="52428800"> <security mode="None"> <transport clientCredentialType="None"/> </security> </binding> </basicHttpBinding> </bindings> <services> <service name="LightSwitchApplication.FtpService"> <endpoint address="FtpService.svc" bindingConfiguration="FtpServiceBinging" binding="basicHttpBinding" contract="IFtpService" /> </service> </services> </system.serviceModel>
这里面我也不是全明白。对应版本是VS2013。照了2015的书试了半天都是错了。上面这个代码是最后修改成功的。最大附件在20M左右。
<binding name="FtpServiceBinging" maxReceivedMessageSize="52428800">这是控制上传文件大小的。不知道为什么目前只能上传到20M。求高手解答。
四、建立client端的脚本(这个好理解)
Private Sub OpenfileUpload() Dispatchers.Main.Invoke( Sub() Dim openDialog As New OpenFileDialog openDialog.Multiselect = False openDialog.Filter = "All File|*.*" If openDialog.ShowDialog = True Then If openDialog.File.OpenRead.Length > 20971520 Then Me.ShowMessageBox("考虑到服务器的存储量,请选择小于20M的文件上传!") Else Dim fileData As FileStream = openDialog.File.OpenRead If fileData.Length > 0 Then Dim fileBArray(fileData.Length - 1) As Byte fileData.Read(fileBArray, 0, fileData.Length) Me.ShowMessageBox(fileData.Length) fileData.Close() fileData.Dispose() Dim ftpupload As New fttp.FtpServiceClient ftpupload.ftpUpAsync("ddd4.txt", fileBArray) End If End If End If End Sub) End Sub
阅读全文
0 0
- Lightswitch文件上传(WCF版)
- LightSwitch文件的上传,下载及保存(数据库版)
- LightSwitch学习--(一)lsml文件
- WCF 文件上传
- WCF上传大文件
- 使用WCF上传文件
- 用WCF上传文件
- Silverlight+WCF上传文件(文件分段,百分比进度条显示)
- WCF上传文件方法总结
- IOS And WCF 上传文件
- lightswitch如何实现文件批量上传功能
- wcf大文件上传配置详解
- WCF实现文件的上传与下载
- flex上传文件到wcf restful
- WCF利用Stream上传大文件
- WCF实现的文件上传和下载
- 利用WCF上传,下载,删除服务器文件
- LightSwitch学习--(一)前言
- 简单通俗解释内外网IP与端口映射
- 浅析js事件冒泡机制
- 十道海量数据处理面试题与十个方法大总结
- [bzoj1007][HNOI2008]水平可见直线(单调栈+几何)
- Qt sender()函数
- Lightswitch文件上传(WCF版)
- php不需要第三个中间变量来实现两个变量的交换
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Python3网络爬虫:初识Scrapy爬虫框架
- python之路字符串操作
- 《王者荣耀》等“爆款”游戏是如何诞生的?| 马晓轶青腾大学演讲
- 商业帝国如何依靠AI出奇制胜?听3000名商界领袖怎么说
- 我们需要为人工智能做一个速度器吗?
- 我的人生,离拥有一个真·机器猫,又近了一步