思路:

1、建立server端的上传模块

2、建立WCF服务接口

3、配置web.config文件

4、建立client端的脚本

一、建立server端的上传过程(废话不多说,直接上代码)

Imports System.Net.WebClient
Imports System.IO
Imports System.Net
Public Module ftpHelperPrivate ReadOnly SMTPuserid As String = "登录名"Private ReadOnly SMTPpassword As String = "登录密码"Public Sub FtpUpload(ByVal filename As String, ByVal byt() As Byte)Dim fwc As New WebClientfwc.Credentials = New NetworkCredential(SMTPuserid, SMTPpassword)Dim add As String = "ftp://bxu2359560474.my3w.com/myfolder/" + filenamefwc.UploadData(add, byt)End Sub
End Module

二、建立WCF服务接口

选择server点右键->添加->新建项->web->WCF服务,输入名称FtpService,此时会建立两个文件(FtpService,IFtpService)。

Imports System.ServiceModel
Imports System.ServiceModel.Activation
' 注意: 使用上下文菜单上的“重命名”命令可以同时更改代码、svc 和配置文件中的类名“FtpService”。
' 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 FtpService.svc 或 FtpService.svc.vb,然后开始调试。
Namespace LightSwitchApplication<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>Public Class FtpServiceImplements IFtpServicePublic Function FtpUpload(filename As String, byt() As Byte) As Boolean Implements IFtpService.ftpUpTryftpHelper.FtpUpload(filename, byt)Catch ex As ExceptionReturn FalseEnd TryReturn TrueEnd FunctionEnd Class
End Namespace
Imports System.ServiceModel
Imports 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 Boolean
End 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 OpenFileDialogopenDialog.Multiselect = FalseopenDialog.Filter = "All File|*.*"If openDialog.ShowDialog = True ThenIf openDialog.File.OpenRead.Length > 20971520 ThenMe.ShowMessageBox("考虑到服务器的存储量,请选择小于20M的文件上传!")ElseDim fileData As FileStream = openDialog.File.OpenReadIf fileData.Length > 0 ThenDim fileBArray(fileData.Length - 1) As BytefileData.Read(fileBArray, 0, fileData.Length)Me.ShowMessageBox(fileData.Length)fileData.Close()fileData.Dispose()Dim ftpupload As New fttp.FtpServiceClientftpupload.ftpUpAsync("ddd4.txt", fileBArray)End IfEnd IfEnd IfEnd Sub)End Sub

Lightswitch文件上传(WCF版)相关推荐

  1. day20 文件上传下载

    2019独角兽企业重金招聘Python工程师标准>>> 文件上传基础及api解析: 文件上传最终版: 文件下载: 转载于:https://my.oschina.net/u/23569 ...

  2. 【问题】vs IIS破除文件上传限制最全版

    原文:[问题]vs IIS破除文件上传限制最全版 今天在测试一下上传文件的时候发现iis和配置存在上传文件大小限制(IIS默认大小30M,最大运行为2g:2147483647),百度了一部分资料有些发 ...

  3. php vsftpd文件上传类,php ftp文件上传函数(基础版)

    php ftp文件上传函数(基础版) 复制代码 代码如下: // 定义变量 $local_file = 'local.zip'; $server_file = 'server.zip'; // 连接F ...

  4. 基于腾讯COS对象存储SDK使用Python编写的文件上传工具第二版

    更多技术文章请访问我的个人博客http://www.rain1024.com NR-TCloud 1.1,更新于2017-02-08 更新说明: 第一版上传时需要将upload.pyc复制到要上传对象 ...

  5. 大神论坛 UEditor 富文本web编辑器最新漏洞版XML文件上传导致存储型XSS

    一.Ueditor最新版XML文件上传导致存储型XSS 测试版本:php版 v1.4.3.3 下载地址:https://github.com/fex-team/ueditor 复现步骤: 1. 上传一 ...

  6. 电脑版终于来了:不限速,支持单个30G大文件上传

    微信搜索逆锋起笔关注后回复编程pdf 领取编程大佬们所推荐的 23 种编程资料! 阿里云盘上传下载不限速,一直备受关注.不过还在公测阶段,官方也没有上线 PC 客户端. 大家期待的阿里云盘桌面端终于上 ...

  7. 若依分离版的文件上传

    若依分离版的文件上传详解 若依文件上传:深度解析若依文件上传操作 若依:文件上传:示例:通过若依自带的文件上传的接口实现文件上传的步骤. 问题描述 近几天在完成一个文件上传和下载的一个需求开发,对于内 ...

  8. MVC+WCF框架下广告位管理——文件上传

    广告位是网站中必不可少的内容之一,也是能直接给我们网站带来经济收益的内容之一.好的广告位不仅不会强宾压主,而会为我们的网站锦上添花,起到画龙点睛的作用,因此设计好广告位也是开发过程中一大重要环节. 最 ...

  9. Ueditor结合七牛云及百度云存储(JAVA版,ueditor-1.4.3)实现图片文件上传

    [前言] 之前研究了ueditor直接上传图片文件到七牛云以及百度云存储,见下面两篇文章: http://uikoo9.com/blog/detail/ueditor-for-bcs http://u ...

最新文章

  1. TensorRT PoolingLayer
  2. 音乐网站购买服务器,怎么样去做一个音乐网站
  3. python中常用的推导(字典推导和列表推导)
  4. c语言创建学生成绩表,C语言创建信息链表,求助
  5. python-docx 如何获取当前字号_调整字号保护视力?专家有一个更好的建议
  6. 关于SIGPIPE导致的程序退出
  7. Gson案例:Java对象与JSON字符串相互转换
  8. 为Android系统定制重启功能
  9. python3+selenium入门03-操作谷歌浏览器
  10. 《语义网基础教程(原书第3版)》—— 导读
  11. 620集成显卡和mx250,独显有必要吗?英特尔UHD620核显对比MX150性能测试
  12. 100位量子计算机算力,最快!我国量子计算机实现算力全球领先
  13. "中国东信杯"广西大学第二届程序设计竞赛(同步赛)
  14. webclient 爬虫bug
  15. matlab分数怎么表示,分子为1的分数怎么输入matlab
  16. 瑞禧靶向光热染料ICG偶联-吲哚菁绿标记Labeled泛素/黑接骨木凝集素SNA / EBL
  17. 拼多多API分享:抓取拼多多商品详情页数据
  18. USB移动硬盘WinPE启动盘的制作方法
  19. windows系统服务器巡检仪哪个工具,机械振动巡检仪功能概述
  20. 计算机三号字在哪个页面,Word用楷体三号一页大约多少字?

热门文章

  1. 曾经狠幸福空间QQ日志-喜欢伤感,甚至颓废
  2. linux安装鼠标选什么软件,Linux如何配置鼠标
  3. 50HZ转60HZ变频电源规格
  4. highcharts去掉右下角highchart.com和右上角的图标(三个小横杆)
  5. JSONPath表达式
  6. 月薪12K运维需要掌握和了解的技术栈
  7. 47.逻辑卷管理2,物理卷详解,pvscan,pvcreate,pvremove,pvchange,pvdisplay
  8. 关于考级和古筝学习--略谈之,有感而发啊
  9. 建立在POP3协议下的Java Email
  10. 【BZOJ4566】找相同字符(后缀数组)