Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在服务代理上检测自动生成的方法参数?_C#_.net_Wcf_Service_Proxy - Fatal编程技术网

C# 如何在服务代理上检测自动生成的方法参数?

C# 如何在服务代理上检测自动生成的方法参数?,c#,.net,wcf,service,proxy,C#,.net,Wcf,Service,Proxy,当我为我的服务创建代理时,一些额外的参数被添加为XmlIgnoreAttribute。例如: 接口方法合同声明: [OperationContract] void AddToList(int integerToAdd); 方法实现: public void AddToList(int integerToAdd) { intList.Add(integerToAdd); } 现在,当我为我的服务动态生成一个代理时,这个方法实际上是这样的: /// <remarks/> [S

当我为我的服务创建代理时,一些额外的参数被添加为XmlIgnoreAttribute。例如:

接口方法合同声明:

[OperationContract]
void AddToList(int integerToAdd);
方法实现:

public void AddToList(int integerToAdd) {
    intList.Add(integerToAdd);
}
现在,当我为我的服务动态生成一个代理时,这个方法实际上是这样的:

/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/IService1/AddToList", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void AddToList(int integerToAdd, [System.Xml.Serialization.XmlIgnoreAttribute()] bool integerToAddSpecified)
{
    this.Invoke("AddToList", new object[] {integerToAdd, integerToAddSpecified});
}
//
[System.Web.Services.Protocols.SoapDocumentMethodAttribute(“http://tempuri.org/IService1/AddToList,RequestNamespace=http://tempuri.org/,ResponseNamespace=http://tempuri.org/,Use=System.Web.Services.Description.SoapBindingUse.Literal,ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void AddToList(int integerToAdd,[System.Xml.Serialization.XmlIgnoreAttribute()]bool integertoads指定)
{
Invoke(“AddToList”,新对象[]{integerToAdd,integertoadspecified});
}
如果我有此参数的ParameterInfo对象,如何检查此参数是否已标记为XmlIgnoreAttribute

如果这不是检查这些自动生成的参数的好方法,那么是否有其他(更好的)方法来检查它们

额外好处:会不会有非布尔类型被生成并标记为XmlIgnoreAttribute的情况?

我想您会使用

(1)我不知道你为什么要检查这些参数,所以不确定它是否好/更好(2)对第二个问题没有把握。我想这是VS code gen(
svcutil
?)可能是一些设计这一功能的微软公司更清楚。

我想你会使用


(1)我不知道你为什么要检查这些参数,所以不确定它是否好/更好(2)对第二个问题没有把握。我假设这是VS code gen(
svcuti
?)中的代码,也许是一些设计此代码的MSFT更清楚。

我正在调用此方法,布尔值是设置整数时需要设置为true的必需参数,因此我想找到一种方法来检测并设置此类型的属性。谢谢我在自定义属性中找到了它,但是,也就是说,你对奖金问题有什么看法吗?LOL只生成标记为XmlIgnoreAttribute的布尔类型?@Alexandru这就是我在
(2)
之后的回答中的意思。您可能会幸运地从构建svcutil的MS团队中找到一些人或认识某个人的人,并通过电子邮件发送给他们。我已经这样做过很多次了,如果你仔细研究的话,它会成功:我正在调用这个方法,布尔值是我设置整数时需要设置为true的一个必需参数,所以我想找到一种方法来检测这种类型的属性并设置它。谢谢我在自定义属性中找到了它,但是,也就是说,你对奖金问题有什么看法吗?LOL只生成标记为XmlIgnoreAttribute的布尔类型?@Alexandru这就是我在
(2)
之后的回答中的意思。您可能会幸运地从构建svcutil的MS团队中找到一些人或认识某个人的人,并通过电子邮件发送给他们。我已经做过很多次了,如果你做得很彻底的话,结果是:D
ParameterInfo secondParam = ..
object[] attribs = 
          secondParam.GetCustomAttributes(typeof(XmlIgnoreAttribute), false);
//the second bool param is ignored. See the docs.
//check if => attribs has anything..