C# 添加到webmethods的额外参数
我正在从wsdl生成的代理读取一些C# 添加到webmethods的额外参数,c#,wcf,reflection,proxy,C#,Wcf,Reflection,Proxy,我正在从wsdl生成的代理读取一些MethodInfo 其中一个方法有三个(int)参数和一个int返回类型,但当我浏览ParameterInfo[]时,我实际上看到了八个参数: Int32 Boolean Int32 Boolean Int32 Boolean Int32& Boolean& 这些额外的参数来自哪里 更新 更详细地说,生成的代理中的代码如下所示: /// <remarks/> [System.Web.Services.Protocols.SoapDocume
MethodInfo
其中一个方法有三个(int
)参数和一个int
返回类型,但当我浏览ParameterInfo[]
时,我实际上看到了八个参数:
Int32
Boolean
Int32
Boolean
Int32
Boolean
Int32&
Boolean&
/// <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]));
}
我最近自己发现了这一点。在某些情况下,它必须处理XSD中的
minoccurs=0
。WCF代理类不使用可为Null的类型,因此XmlSerializer无法确定是否要发送某个字段
您可以设置一个,但它不会被发送。您还必须将oneSpecified
设置为true
,以使序列化程序序列化one
的值并发送它
更多信息。您使用什么来获取MethodInfo?你确定这是同样的方法吗?例如,这里的方法名是什么?基本上:请提供更多上下文基本上我只是在代码中生成了一个代理程序集,并通过反射读取它。我自己也写了这个Web服务,其实也是同样的方法。当我从VS2008搬到VS2010的时候,我自己也遇到了类似的问题。伟大的答案!
if (!parameterInfo[i].Name.EndsWith("Specified") && !parameterInfo[i].IsRetval && !parameterInfo[i].Name.EndsWith("Result"))
{
// magic
}