至於爲什麼會導致參數增多的情況呢?經過測試發現只要是用C# .NET開發的WEB服務就不會出現此問題(這點也很容易理解,用C#工具發佈,再由C#工具引用加載肯定不會有問題);而我們的geoweb服務是是用JAVA開發的,用C# .NET調用;出現問題也很正常。
該問題的產生背景:
.net向webservice傳double、int、datetime到服務器,而得到的返回值爲null的情況,比如用C#.NET調用Java開發的WebService時,先在客戶端封裝的帶有int屬性的對象,當將該對象傳到服務器端時,服務器端可以得到string類型的屬性值,卻不能得到int類型、double和DateTime類型的值(在服務端得到的均爲null)。
解決辦法:
VS2005封裝WebService引用時,如果WebService發佈的是一個基本數據類型組成的對象,則會對該對象的非string屬性同時生成兩個屬性,一般是這樣的"屬性××"、"屬性××Specified"。而"屬性名Specified"是一個bool類型,只有這個屬性被設置成true時,"屬性××"的值纔會被序列化成xml傳遞。
綜上所述,參數增多是VS2005爲了解決C# .NET調用JAVA開發的Web服務過程中服務端接收的參數爲NULL的BUG。
故參數增多不會影響到程序的正確運行,傳入的參數基本上多就是一些boolean(布爾);全部傳true即可得到正確的結果
例如(SoapUI和VS2005調用web服務區別):
Ø 用SoapUI調用,接口參數是正常的;soapUI是用JAVA語言開發的,相當於是用JAVA調用web服務(該web服務的JAVA開發的)。
Request(請求串):
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://webservice.geoglobe.geostar.com">
<soap:Header/>
<soap:Body>
<web:getRightId>
<!--Optional:-->
<web:rightitem>添加</web:rightitem>
<!--Optional:-->
<web:rightparentid>1</web:rightparentid>
<!--Optional:-->
<web:sysid>1</web:sysid>
</web:getRightId>
</soap:Body>
</soap:Envelope>
-------------------------------------------------------------------------------------------------------
Resposne(返回信息串)
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns:getRightIdResponse xmlns:ns="http://webservice.geoglobe.geostar.com">
<ns:return>1</ns:return>
</ns:getRightIdResponse>
</soapenv:Body>
</soapenv:Envelope>
Ø 用VS2005調用加載進來的web服務,接口參數是變多了;用C#.NET調用web服務(該web服務的JAVA開發的)
接口:public void getRightId(string rightitem, int rightparentid, bool rightparentidSpecified, int sysid, bool sysidSpecified, out int return, out bool returnSpecified)
程序調用示例:
localRightManager.RightManagerWebService sa = new WindowsApplication1.localRightManager.RightManagerWebService();
int returnVal;
bool returnBoolVal;
sa.getRightId("添加",1,true,1,true,out returnVal, out returnBoolVal);
rightparentidSpecified設置爲true是爲了讓服務端能正確的接收到rightparentid的值;
sysidSpecified設置爲true是爲了讓服務端能正確的接收到sysid的值;
運行完此程序之後returnVal的值爲1,returnBoolVal的值爲true。
此例子說被VS2005加載進來的接口,參數確實增多了,這個接口參數增加了4個之多