-
大小: 132KB文件類型: .zip金幣: 2下載: 0 次發布日期: 2022-10-03
- 語言: C#
- 標簽: ASP.NET??WebService??
資源簡介
使用 ASP.NET/C# 實現的 WebService。用于接收來自客戶端REST方式上傳的照片和說明。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Web;
using?System.Web.Services;
using?System.xml;
using?System.IO;
using?System.Text;
using?System.Collections.Specialized;
namespace?FirstPlace
{
????///?
????///?Summary?description?for?PhotoNotes
????///?
????[WebService(Namespace?=?“http://www.sunyong.com.cn/JieSi/FirstPlace“)]
????[WebServiceBinding(ConformsTo?=?WsiProfiles.BasicProfile1_1)]
????[System.ComponentModel.ToolboxItem(false)]
????//?To?allow?this?Web?Service?to?be?called?from?script?using?ASP.NET?AJAX?uncomment?the?following?line.?
????//?[System.Web.script.Services.scriptService]
????public?class?PhotoNotes?:?System.Web.Services.WebService
????{
????????[WebMethod]
????????public?xmlDocument?UploadData()
????????{
????????????StringBuilder?sb?=?new?StringBuilder();
????????????string?result?=?string.Empty;
????????????try
????????????{
????????????????HttpFileCollection?httpFiles?=?Context.Request.Files;
????????????????HttpPostedFile?filePhoto?=?httpFiles[“media“];
????????????????string?localPhotoFile?=?Path.Combine(Server.MapPath(“.“)?filePhoto.FileName);
????????????????filePhoto.SaveAs(localPhotoFile);
????????????????
????????????????NameValueCollection?formVars?=?Context.Request.Form;
????????????????string?hdrMsg?=?formVars[“message“];
????????????????string?msgFile?=?string.Format(“{0}.{1}“?Path.GetFileNameWithoutExtension(filePhoto.FileName)?“txt“);
????????????????string?localMsgFile?=?Path.Combine(Server.MapPath(“.“)?msgFile);
????????????????using?(StreamWriter?sw?=?File.Exists(localMsgFile)???File.CreateText(localMsgFile)?:?new?StreamWriter(localMsgFile))
????????????????{
????????????????????sw.WriteLine(string.Format(“[{0}]?{1}:?{2}“?DateTime.Now?filePhoto.FileName?hdrMsg));
????????????????}
????????????????result?=?“success“;
????????????}
????????????catch?(System.Exception?ex)
????????????{
????????????????result?=?string.Format(“fail:?{0}“?ex);
????????????}
????????????sb.AppendFormat(“l>{0} l>“?result);
????????????xmlDocument?xmlDoc?=?new?xmlDocument();
????????????xmlDoc.Loadxml(sb.ToString());
????????????return?xmlDoc;
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-02-01?14:02??FirstPlace\
?????目錄???????????0??2012-02-01?16:50??FirstPlace\FirstPlace\
?????文件?????????920??2012-02-01?14:02??FirstPlace\FirstPlace.sln
?????文件???????15872??2012-02-01?16:50??FirstPlace\FirstPlace.suo
?????目錄???????????0??2012-02-01?14:02??FirstPlace\FirstPlace\App_Data\
?????文件????????4101??2012-02-01?14:03??FirstPlace\FirstPlace\FirstPlace.csproj
?????文件????????1297??2012-02-01?14:03??FirstPlace\FirstPlace\FirstPlace.csproj.user
?????文件??????124662??2012-02-01?16:02??FirstPlace\FirstPlace\image.jpg
?????文件?????????562??2012-02-01?16:02??FirstPlace\FirstPlace\image.txt
?????文件??????????96??2012-02-01?14:03??FirstPlace\FirstPlace\PhotoNotes.asmx
?????文件????????2246??2012-02-01?16:01??FirstPlace\FirstPlace\PhotoNotes.asmx.cs
?????目錄???????????0??2012-02-01?14:02??FirstPlace\FirstPlace\Properties\
?????文件????????1391??2012-02-01?14:02??FirstPlace\FirstPlace\Properties\AssemblyInfo.cs
?????文件????????8061??2012-02-01?14:43??FirstPlace\FirstPlace\Web.config
評論
共有 條評論