如何在WebService中過載方法

2021-07-13 08:15:58 字數 1770 閱讀 6062

1. 本來在webservice中這樣寫的過載方法,如下所示:

[webservice(namespace = "")]

[webservicebinding(conformsto = wsiprofiles.basicprofile1_1)]

public class dataobjectwebservice : system.web.services.webservice

[webmethod(enablesession = true)]

public int add(int a, int b, int c)

}在呼叫webservice時,拋錯:「int32 add(int32, int32, int32) 和 int32 add(int32, int32) 同時使用訊息名稱「add」。使用 webmethod 自定義特性的 messagename 屬性為方法指定唯一的訊息名稱。」

2. 原來,必須在類中指示不支援1.1標準並且在方法中指定messagename來建立唯一的別名。可以這樣來解決,如下所示,這樣在客戶端呼叫時,就可以呼叫webservice不同的過載方法了。

[webservice(namespace = "")]

[webservicebinding(conformsto = wsiprofiles.none)]

public class dataobjectwebservice : system.web.services.webservice

[webmethod(enablesession = true, messagename= "add2")]

public int add(int a, int b, int c)

}其中,

webservicebindingattribute.conformsto 屬性:獲取或設定繫結聲稱所符合的 web 服務互操作性 (wsi) 規範。

wsiprofiles.none 表示 web 服務未提出任何一致性聲稱。

wsiprofiles.basicprofile1_1 表示 web 服務聲稱符合「wsi 基本概要」1.1 版。

webmethodattribute.messagename 屬性:在傳遞到 xml web services 方法和從 xml web services 方法返回的資料中用於 xml web services 方法的名稱。預設值是 xml web services 方法的名稱。 另外,messagename屬性可用於為方法或屬性名建立別名。messagename屬性 (property) 最常用來唯一標識多型方法。預設情況下,messagename設定為 xml web services 方法的名稱。因此,如果 xml web services 包含兩個或更多同名的 xml web services 方法,則可唯一確定各個 xml web services 方法,處理方法是將messagename設定為 xml web services 內的唯一名稱,而不用在**中更改實際方法的名稱。資料在傳遞到 xml web services 時通過請求傳送,而在返回時則通過響應傳送。在請求和響應中,用於 xml web services 方法的名稱是其messagename屬性 (property)。與 xml web services 方法關聯的訊息名稱必須在 xml web services 內是唯一的。如果在客戶端呼叫初始方法後新增同名但具有不同引數的新 xml web services 方法,則應為新方法指定不同的訊息名稱,但應原樣保留初始訊息名稱,以確保與現有客戶端相容。

如何在C 中使用WebService

將他解壓後,進入到資料夾 gsoap 2.8.18 gsoap 2.8 gsoap bin win32 裡面有2個我們要用到的exe,wsdl2h.exe和soapcpp2.exe,如果缺少乙個typemap.dat,則從gsoap 2.8.18 gsoap 2.8 gsoap下拷貝進來,最後就可以...

如何在程式中關閉 重起和硬起動WCE PPC SP

關閉 suspend 方法1 虛擬關機鍵 keybd event vk off,0,0,0 keybd event vk off,0,keyeventf keyup,0 方法2 呼叫未公開函式poweroffsystem extern c declspec dllimport void powero...

如何在程式中延時

方法一 使用sleep函式,如延時2秒,用sleep 2000 方法二 使用sleep函式的不利在於延時期間不能處理其他的訊息,如果時間太長,就好象宕機一樣,利用coledatetime類和coledatetimespan類實現延時就不會出現那樣的問題 coledatetime start time...