WCF:有没有尽在OperationContract的参数所需的属性? [英] WCF: is there an attribute to make parameters in the OperationContract required?
问题描述
我用 [数据成员(IsRequired = TRUE)]
进行必要的DataContract属性。似乎没有被一些IsRequired为OperationContract的参数。如何使他们所需的,而不是允许空?
在OperationContract的所述的参数似乎是在了SoapUI工具可选的。虽然这绝不是可选的或空。
WCF接口:
[OperationContract的]
IsClientUpdateRequiredResult IsClientUpdateRequired(IsClientUpdateRequiredInput versie);...[DataContract]
公共类IsClientUpdateRequiredInput
{
[数据成员(IsRequired =真)]
公共字符串CLIENTNAME {搞定;组; }
[数据成员(IsRequired = TRUE,令= 0)]
公众诠释重大{搞定;组; }
[数据成员(IsRequired = TRUE,订单= 1)]
公众诠释轻微{搞定;组; }
[数据成员(IsRequired = TRUE,令= 2)]
公众诠释构建{搞定;组; }
[数据成员(IsRequired = TRUE,令= 3)]
公众诠释修订{搞定;组; }
}
的soapUI请求模板:
<肥皂:信封的xmlns:SOAP =http://www.w3.org/2003/05/soap-envelope的xmlns:TEM =HTTP:// tempuri .ORG /的xmlns:PIR =http://schemas.datacontract.org/2004/07/PirIS.Web.WCF.InputClasses>
<肥皂:页眉/>
<肥皂:身体与GT;
< TEM:IsClientUpdateRequired>
< - 可选:! - >
< TEM:versie>
< PIR:CLIENTNAME>< / PIR:CLIENTNAME>
< PIR:大>< / PIR:大>
< PIR:轻微>< / PIR:轻微>
< PIR:打造>< / PIR:打造>
< PIR:修订>< / PIR:修订>
< / TEM:versie>
< / TEM:IsClientUpdateRequired>
< / SOAP:身体与GT;
< / SOAP:信封>
不幸的是,不能使用默认的WCF来完成。存在几个解决方法:
- 自定义
RequiredParametersBehavior
属性 - 使用验证应用程序块从企业库和规则集关联到你的方法
但是,您可以实现一个FaultContract并抛出一个错误,当输入参数为null。
I use [DataMember(IsRequired=true)]
to make the DataContract properties required. There doesn't seem to be some IsRequired for the OperationContract parameters. How do I make them required and not allow null?
The parameter in of OperationContract appears to be optional in SoapUI tool. Though this must never be optional or null.
WCF Interface:
[OperationContract]
IsClientUpdateRequiredResult IsClientUpdateRequired(IsClientUpdateRequiredInput versie);
...
[DataContract]
public class IsClientUpdateRequiredInput
{
[DataMember(IsRequired=true)]
public string clientName { get; set; }
[DataMember(IsRequired = true, Order = 0)]
public int major { get; set; }
[DataMember(IsRequired = true, Order = 1)]
public int minor { get; set; }
[DataMember(IsRequired = true, Order = 2)]
public int build { get; set; }
[DataMember(IsRequired = true, Order = 3)]
public int revision { get; set; }
}
soapUI request template:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/" xmlns:pir="http://schemas.datacontract.org/2004/07/PirIS.Web.WCF.InputClasses">
<soap:Header/>
<soap:Body>
<tem:IsClientUpdateRequired>
<!--Optional:-->
<tem:versie>
<pir:clientName>?</pir:clientName>
<pir:major>?</pir:major>
<pir:minor>?</pir:minor>
<pir:build>?</pir:build>
<pir:revision>?</pir:revision>
</tem:versie>
</tem:IsClientUpdateRequired>
</soap:Body>
</soap:Envelope>
Unfortunately it can't be done using default WCF. There exist a few workarounds:
- A custom
RequiredParametersBehavior
attribute - Using the Validation Application Block from the Enterprise Library and associate a ruleset to your method
You can however implement a FaultContract and throw a fault when the input parameter is null.
这篇关于WCF:有没有尽在OperationContract的参数所需的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!