我使用 WCF 创建了一个 Web 服务。 我不知道如何通过数据协定在 WSDL/XSD 中设置约束和限制。
如果我使用约束改进 XSD2 架构,然后将此自定义架构绑定(bind)到现有服务,会怎样?如果是这样,我怎样才能使服务公开改进的 WSDL? 否则,有没有其他方法可以为 WCF 服务设置元数据?
最佳答案
请不要混淆 XSD 和 WSDL - this is totally different things
根据您的问题 - 尝试使用 RiaServices .它允许你编写这样的代码
public class Meeting
{
[Key]
public int MeetingId { get; set; }
[Required]
public DateTime Start { get; set; }
[Required]
public DateTime End { get; set; }
[Required]
[StringLength(80, MinimumLength = 5)]
public string Title { get; set; }
public string Details { get; set; }
[Required]
[RegularExpression(@"\d{1,3}/\d{4}",
ErrorMessage = "{0} must be in the format of 'Building/Room'")]
public string Location { get; set; }
[Range(2, 100)]
[Display(Name = "Minimum Attendees")]
public int MinimumAttendees { get; set; }
[Range(2, 100)]
[Display(Name = "Maximum Attendees")]
public int MaximumAttendees { get; set; }
}
据我所知,使用约束和限制改进 WSDL 的唯一方法是使用限制属性标记您的 DataContract 类(如果不正确请修复我)
关于c# - 将自定义 WSDL 绑定(bind)到现有 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11099335/