2011-11-15 31 views
2

我正在從wsdl生成的代理中讀取一些MethodInfo將額外參數添加到web方法

其中一種方法有三種(int)參數和int返回類型,但是當我探索ParameterInfo[]我居然看到八個參數:

  • Int32
  • Boolean
  • Int32
  • Boolean
  • Int32
  • Boolean
  • Int32&
  • Boolean&

在哪裏,這些額外的參數產生的?

UPDATE

更詳細地說明了一下,在生成的代理代碼如下如下:

/// <remarks/> 
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/IInleerAppService/AddThreeNumbers", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] 
public void AddThreeNumbers(int one, [System.Xml.Serialization.XmlIgnoreAttribute()] bool oneSpecified, int two, [System.Xml.Serialization.XmlIgnoreAttribute()] bool twoSpecified, int three, [System.Xml.Serialization.XmlIgnoreAttribute()] bool threeSpecified, out int AddThreeNumbersResult, [System.Xml.Serialization.XmlIgnoreAttribute()] out bool AddThreeNumbersResultSpecified) { 
    object[] results = this.Invoke("AddThreeNumbers", new object[] { 
       one, 
       oneSpecified, 
       two, 
       twoSpecified, 
       three, 
       threeSpecified}); 
    AddThreeNumbersResult = ((int)(results[0])); 
    AddThreeNumbersResultSpecified = ((bool)(results[1])); 
} 

這是爲什麼?

UPDATE

如果你被這個竊聽,因爲我,你很容易甘蔗避免簡單地將下面的代碼片斷顯示這些額外的參數:

if (!parameterInfo[i].Name.EndsWith("Specified") && !parameterInfo[i].IsRetval && !parameterInfo[i].Name.EndsWith("Result")) 
{ 
    // magic 
} 
+0

你用什麼來獲取MethodInfo?你確定這是同樣的方法嗎?例如,這裏的方法名稱是什麼?基本上:更多的上下文請 –

+0

基本上我只是在代碼中生成代理程序集並通過反射讀取它。我自己也寫了webservice,它的確是同樣的方法。 – Oxymoron

回答

3

最近我發現了這一點爲了我自己。在某些情況下,它與XSD中的minoccurs=0有關。 WCF代理類不使用可爲空的類型,因此XmlSerializer無法確定您是否想要發送某個字段。

您可以設置one,但不會發送。您還必須將oneSpecified設置爲true以使串行器序列化值one併發送它。

一些更多的信息here

+1

當我從VS 2008移至VS 2010時,我自己遇到過類似的問題。很棒的回答CodeCaster! –