I wrote an example for uploading files through Web services. If you are free, take a look.
I wrote an example just now. I tried to use WebService to upload files. You can also paste the example here:
Server code:
The server code implements a simple uploadfile method, which receives byte [] arrays. I have not tried other types. It is estimated that filestream is too difficult to use, but it is easy to use simple types, the second parameter is the relative path to be saved. After the method is executed, the physical file path on the server is returned. it's easy to write. Sorry. just understand the meaning.
Using system; using system. web; using system. collections; using system. web. services; using system. web. services. protocols; using system. io; // Summary of uploadservice // [WebService (namespace = "http://tempuri.org/")] [webservicebinding (conformsto = wsiprofiles. basicprofile1_1)] public class uploadservice: system. web. services. webService {public uploadservice () {// If the designed component is used, uncomment the following line // initializecomponent ();} [webmethod] Public String uploadfile (byte [] file, string path) {try {string phypath = server. mappath (PATH); filestream FS = new filestream (phypath, filemode. create, fileaccess. write); FS. write (file, 0, file. length); FS. close (); Return phypath;} catch (exception ex) {Throw ex ;}}}
Client Call Code: (add a web reference to point to the asmx file, such as http: // localhost: 2339/testsite/uploadservice. asmx)
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;namespace ServiceTest{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button2_Click(object sender, EventArgs e){openFileDialog1.ShowDialog(this);textBox1.Text = openFileDialog1.FileName;}private void button1_Click(object sender, EventArgs e){FileStream fs = File.OpenRead(textBox1.Text);byte[] file = new byte[fs.Length];fs.Read(file, 0, file.Length);localhost.UploadService us = new ServiceTest.localhost.UploadService();textBox2.Text = us.UploadFile(file, Path.GetFileName(textBox1.Text));}}}
There are no special cases to make too many judgments. A WebService is added to the web project, and a winform project is written from the local machine to call the service, note that when uploading large files. modify the configuration as follows: (Note httpruntime)
<System. Web>
Reference address: http://www.openzone.cn/blogs/opennet/archive/2006/07/23/34.aspx