Windows Mobile開發之動態調用WebServcie

來源:互聯網
上載者:User

轉載地址:

http://www.cnblogs.com/lhuser/articles/1508152.html

最近在做一個手機用戶端項目開發.用戶端作業系統是Windows Mobile 6.0 ,伺服器端作業系統是:Windows Server 2003.功能是:擷取手機上攝像機或者照片和視頻通過網路傳回伺服器端.對於圖片和視頻傳輸過程,我考慮了兩種方法,一種是在用C/S模式,就是用戶端和伺服器端用Windows Socket傳輸檔案,另一種是在伺服器上建立Web Service來接收用戶端上傳的檔案.因為,伺服器端最終的應用是建立在Web 程式上的,而且我個人對Socket開發不是很熟悉,所以,先擇了用Web
Service 的方式.

而應用這種方式要考慮的問題就是程式移植部署時,用戶端程式對Web 服務的動態引用問題.

我的實現方法如下:

用Vs.net添加Web引用後,執行個體化該類,在執行個體化語句中,右擊該類類名,在快顯功能表中選擇"轉到定義",可以看到類似於以下的代碼:

Code//------------------------------------------------------------------------------// <auto-generated>//     此代碼由工具產生。//     運行庫版本:2.0.50727.42////     對此檔案的更改可能會導致不正確的行為,並且如果//     重建代碼,這些更改將會丟失。// </auto-generated>//------------------------------------------------------------------------------// // 此原始碼是由 Microsoft.CompactFramework.Design.Data 2.0.50727.42 版自動產生。// namespace FileOperation.FileUpload {    using System.Diagnostics;    using System.Web.Services;    using System.ComponentModel;    using System.Web.Services.Protocols;    using System;    using System.Xml.Serialization;            /**//// <remarks/>    [System.Diagnostics.DebuggerStepThroughAttribute()]    [System.ComponentModel.DesignerCategoryAttribute("code")]    [System.Web.Services.WebServiceBindingAttribute(Name="FileUploadSoap", Namespace="http://tempuri.org/")]    public partial class FileUpload : System.Web.Services.Protocols.SoapHttpClientProtocol {                /**//// <remarks/>        public FileUpload() {            this.Url = "http://localhost/gpsgoogle/FileUpload.asmx";        }                /**//// <remarks/>        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/HelloWorld", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]        public string HelloWorld() {            object[] results = this.Invoke("HelloWorld", new object[0]);            return ((string)(results[0]));        }                /**//// <remarks/>        public System.IAsyncResult BeginHelloWorld(System.AsyncCallback callback, object asyncState) {            return this.BeginInvoke("HelloWorld", new object[0], callback, asyncState);        }                /**//// <remarks/>        public string EndHelloWorld(System.IAsyncResult asyncResult) {            object[] results = this.EndInvoke(asyncResult);            return ((string)(results[0]));        }                /**//// <remarks/>        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/UploadFile", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]        public string UploadFile([System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] byte[] data, string fileName) {            object[] results = this.Invoke("UploadFile", new object[] {                        data,                        fileName});            return ((string)(results[0]));        }                /**//// <remarks/>        public System.IAsyncResult BeginUploadFile(byte[] data, string fileName, System.AsyncCallback callback, object asyncState) {            return this.BeginInvoke("UploadFile", new object[] {                        data,                        fileName}, callback, asyncState);        }                /**//// <remarks/>        public string EndUploadFile(System.IAsyncResult asyncResult) {            object[] results = this.EndInvoke(asyncResult);            return ((string)(results[0]));        }    }}

其中,可以看到該類的建構函式,是一個沒有參數的建構函式,其中函數中用預設值會它的Url欄位賦值.因些,我們可以給它增加一個帶參數的建構函式,其中參數為Web引用的Url.如下

 

public FileUpload(string url)        {           this.Url = url;        }

這樣做以後,我們可以用如下語句執行個體化該類:

string url = @"http://192.168.0.55/FileUpload.asmx";            FileUpload.FileUpload fileUpload = new FileOperation.FileUpload.FileUpload(url);

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.