天天看點

c#調用webservices

有兩種方式,靜态調用(添加web服務的暫且這樣定義)和動态調用:

靜态調用:

使用添加web服務的方式支援各種參數,由于vs2010會自動轉換,會生成一個特定的Reference.cs類檔案

動态調用:

通過soap/get/post方法動态調用webservices,隻支援string類型或數組類型

否則執行

XmlSerializer mySerializer = new XmlSerializer(o.GetType());

會報錯:

不支援類型 System.Collections.Hashtable,因為它實作 IDictionary。

說明:靜态調用也是将其它資料類型轉換成Object[]類型的數組來傳參

譬如java中HashMap類型,vs2010轉換後的情況如下:

Reference.cs:

調用:

localhost.CreateGevtIncidentService client = new localhost.CreateGevtIncidentService();

localhost.anyType2anyTypeMapEntry atatm1 = new localhost.anyType2anyTypeMapEntry();

localhost.anyType2anyTypeMapEntry atatm2 = new localhost.anyType2anyTypeMapEntry();

atatm1.key = "title";

atatm1.value = "test title";

atatm2.key = "content";

atatm2.value = "testContent";

localhost.anyType2anyTypeMapEntry[] test=client.createIncident(new localhost.anyType2anyTypeMapEntry[] { atatm1,atatm2});

logger.Info(test.ToString());