您好,登錄后才能下訂單哦!
- /async 同時(shí)生成同步和異步方法簽名。
默認(rèn)設(shè)置:只生成同步方法簽名。
縮寫形式:/a
- /tcv:Version35
指定應(yīng)用程序針對 .NET Framework 的哪個(gè)版本。有效值為:Version30 和 Version35。默認(rèn)值為 Version30。
縮寫形式:/tcv
Version30:如果為使用 .NET Framework 3.0 的客戶端生成代碼,則使用 /tcv:Version30。
Version35:如果為使用 .NET Framework 3.5 的客戶端生成代碼,則使用 /tcv:Version35。如果將 /tcv:Version35
與 /async 開關(guān)一起使用,則會(huì)同時(shí)生成基于事件的異步方法和基于回調(diào)/委托的異步方法。
- /collectionType:<類型>
從架構(gòu)中生成代碼時(shí),指定要用作集合數(shù)據(jù)類型的完全限定或程序集限定名稱。
縮寫形式:/ct
- /reference:<文件路徑>
引用指定程序集中的類型。在生成客戶端時(shí),使用此選項(xiàng)來指定可能包含類型的程序集,這些類型表示所導(dǎo)入的元數(shù)據(jù)
。
無法使用此開關(guān)指定消息協(xié)定和 XmlSerializer 類型。
如果引用了 DateTimeOffset,則會(huì)使用此類型,而不是生成新類型。如果應(yīng)用程序是使用 .NET Framework 3.5 編寫
的,則 SvcUtil.exe 會(huì)自動(dòng)引用 DateTimeOffset。
縮寫形式:/r
- /enableDataBinding
在所有數(shù)據(jù)協(xié)定類型上實(shí)現(xiàn) INotifyPropertyChanged 接口以啟用數(shù)據(jù)綁定。
縮寫形式:/edb
生成同步,帶事件的異步代碼,集合使用System.Collections.ObjectModel.ObservableCollection集合,指定程序集引用
- svcutil /a /d:d:/temp http://localhost:1998/Implement/AgriProductService.svc /ser:DataContractSerializer
- /tcv:Version35 /ct:System.Collections.ObjectModel.ObservableCollection`1 /reference:C:/"Program
- Files"/"Reference Assemblies"/Microsoft/Framework/.NETFramework/v4.0/WindowsBase.dll
生成同步,帶事件的異步代碼,集合使用System.Collections.Generic.List集合
- svcutil /a /d:d:/temp http://localhost:1998/Implement/AgriProductService.svc /ser:DataContractSerializer
- /tcv:Version35 /ct:System.Collections.Generic.List`1
生成同步,帶事件的異步代碼,集合映射為數(shù)組
- svcutil /a /d:d:/temp http://localhost:1998/Implement/AgriProductService.svc /ser:DataContractSerializer
- /tcv:Version35
關(guān)于svcutil.exe的詳細(xì)介紹,可以參看微軟的MSDN。
ServiceModel 元數(shù)據(jù)實(shí)用工具 (Svcutil.exe)
如果生成的代理類是要給silverlight用,還需要手動(dòng)修改一下。因?yàn)閟ilverlight不支持同步操作,所有需要?jiǎng)h除代理類中的同步操作的代碼,只保留異步的代碼,還有就是需要添加下面的代碼,用于open和close客戶端的代碼。
要是有只生成異步代碼的參數(shù)就更好了,好像目前還沒有發(fā)現(xiàn),默認(rèn)生成同步代碼,加上/async參數(shù)就同時(shí)生成異步代碼。
下面的代碼添加到client類中,public partial class Service1Client : System.ServiceModel.ClientBase<IService1>, IService1,這個(gè)類中。
- private BeginOperationDelegate onBeginOpenDelegate;
- private EndOperationDelegate onEndOpenDelegate;
- private System.Threading.SendOrPostCallback onOpenCompletedDelegate;
- private BeginOperationDelegate onBeginCloseDelegate;
- private EndOperationDelegate onEndCloseDelegate;
- private System.Threading.SendOrPostCallback onCloseCompletedDelegate;
- public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> OpenCompleted;
- public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> CloseCompleted;
- private System.IAsyncResult OnBeginOpen(object[] inValues, System.AsyncCallback callback, object asyncState)
- {
- return ((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(callback, asyncState);
- }
- private object[] OnEndOpen(System.IAsyncResult result)
- {
- ((System.ServiceModel.ICommunicationObject)(this)).EndOpen(result); return null;
- }
- private void OnOpenCompleted(object state)
- {
- if ((this.OpenCompleted != null))
- {
- InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
- this.OpenCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
- }
- }
- public void OpenAsync()
- {
- this.OpenAsync(null);
- }
- public void OpenAsync(object userState)
- {
- if ((this.onBeginOpenDelegate == null))
- {
- this.onBeginOpenDelegate = new BeginOperationDelegate(this.OnBeginOpen);
- }
- if ((this.onEndOpenDelegate == null))
- {
- this.onEndOpenDelegate = new EndOperationDelegate(this.OnEndOpen);
- }
- if ((this.onOpenCompletedDelegate == null))
- {
- this.onOpenCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnOpenCompleted);
- }
- base.InvokeAsync(this.onBeginOpenDelegate, null, this.onEndOpenDelegate, this.onOpenCompletedDelegate, userState);
- }
- private System.IAsyncResult OnBeginClose(object[] inValues, System.AsyncCallback callback, object asyncState)
- {
- return ((System.ServiceModel.ICommunicationObject)(this)).BeginClose(callback, asyncState);
- }
- private object[] OnEndClose(System.IAsyncResult result)
- {
- ((System.ServiceModel.ICommunicationObject)(this)).EndClose(result); return null;
- }
- private void OnCloseCompleted(object state)
- {
- if ((this.CloseCompleted != null))
- {
- InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
- this.CloseCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
- }
- }
- public void CloseAsync()
- {
- this.CloseAsync(null);
- }
- public void CloseAsync(object userState)
- {
- if ((this.onBeginCloseDelegate == null))
- {
- this.onBeginCloseDelegate = new BeginOperationDelegate(this.OnBeginClose);
- }
- if ((this.onEndCloseDelegate == null))
- {
- this.onEndCloseDelegate = new EndOperationDelegate(this.OnEndClose);
- }
- if ((this.onCloseCompletedDelegate == null))
- {
- this.onCloseCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnCloseCompleted);
- }
- base.InvokeAsync(this.onBeginCloseDelegate, null, this.onEndCloseDelegate, this.onCloseCompletedDelegate, userState);
- }
還要提醒大家的是,用svcutil生成的異步訪問代碼,直接給silverlight使用,還有有點(diǎn)問題的。和使用VS2010添加服務(wù)生成的代碼相比,有一些出入,比如沒有實(shí)現(xiàn)ChannelBase,沒有在Client中override CreateChannel方法,還有一些局部的差異,導(dǎo)致使用起來會(huì)有一些不同。
出現(xiàn)上面的問題,不知道是我沒有用對svcutil的參數(shù),還是它們本身就是有一些不同的。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。