Because the project needs, through the local client, the picture is uploaded to the website. Through WebService.
This is the client code:
1 Private voidBtnimg_click (Objectsender, EventArgs e)2 {3 This. Yanzheng ();4Mylocalhost. Mysoapheader MyHeader =NewMylocalhost. Mysoapheader ();///this is SoapHeader .5Mylocalhost. MyWebService MyService =NewMylocalhost. MyWebService ();//Invoke Service6Myservice.mysoapheadervalue =MyHeader;7 Openfiledialog1.showdialog ();8pictureBox1.Image =Image.FromFile (openfiledialog1.filename);9 stringName= This. textBox1.Text.ToString ();TenMyservice.createfiles (name, Photoimageinsert (pictureBox1.Image));//picture name, picture byte stream OneMessageBox.Show (Openfiledialog1.filename);//file Local Path AMessageBox.Show ("saved successfully"); - } - the /// <summary> - ///Convert Image object to byte[] byte stream - /// </summary> - /// <param name= "Imgphoto" >Image object, which is the uploaded image</param> + /// <returns>byte[] Byte stream</returns> - Public byte[] Photoimageinsert (System.Drawing.Image imgphoto) + { A //convert image to stream data and save as byte[] atMemoryStream Mstream =NewMemoryStream (); - Imgphoto.save (Mstream, System.Drawing.Imaging.ImageFormat.Png); - byte[] Bydata =NewByte[mstream. Length]; -Mstream. Position =0; -Mstream. Read (Bydata,0, bydata.length); - Mstream. Close (); in returnBydata; -}
Service-Side code:
1 /// <summary>2 ///How to generate picture files from the byte stream in the service3 /// </summary>4 /// <param name= "Imgname" >Picture name</param>5 /// <param name= "FormData" >Data Flow</param>6[System.Web.Services.Protocols.SoapHeader ("Header")]//SOAP headers for user authentication7[WebMethod (Description ="Create a picture", enablesession =true)]8 Public voidCreatefiles (stringImgname,byte[] FormData)9 {Ten //Picture Generation Path One stringPath = HttpContext.Current.Server.MapPath ("") +@"/.. /jajaweixinqianduanweb/uploadcaipinimages/"+ Imgname +". jpg"; ABinaryWriter bw =NewBinaryWriter (file.create (Path, formdata.length, fileoptions.asynchronous)); -Bw. Write (FormData);//get the uploaded picture and save it - bw. Close (); the}