使用服务引用代理的自定义属性
我向用作 Web 服务一部分的枚举添加了一个自定义属性。当我将 Web 服务作为服务引用添加到 win 表单应用程序时,自定义属性不会出现在服务引用代理对象中,尽管枚举类型本身确实出现了。我已经查看了所有内容,但没有找到任何接近解决方案的内容。
我是否正在尝试做一些不可能的事情?
服务器端代码:
public enum ServiceEnum
{
[ServiceEnumTest("Boat")]item1,
[ServiceEnumTest("Plane")]item2,
[ServiceEnumTest("Bicycle")]item3,
[ServiceEnumTest("Car")]item4,
item5
}
客户端代理生成的代码:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="ServiceEnum", Namespace="http://tempuri.org/")]
public enum ServiceEnum : int {
[System.Runtime.Serialization.EnumMemberAttribute()]
item1 = 0,
[System.Runtime.Serialization.EnumMemberAttribute()]
item2 = 1,
[System.Runtime.Serialization.EnumMemberAttribute()]
item3 = 2,
[System.Runtime.Serialization.EnumMemberAttribute()]
item4 = 3,
[System.Runtime.Serialization.EnumMemberAttribute()]
item5 = 4,
}
I added a custom attribute to an enum that I was using as part of a web service. When I add the web service as a service reference to a win forms application the custom attributes do not appear in the service reference proxy objects although the enum type itself does appear. I've looked all over and haven't found anything close to a solution.
Am I trying to do something that is not possible?
Server side code:
public enum ServiceEnum
{
[ServiceEnumTest("Boat")]item1,
[ServiceEnumTest("Plane")]item2,
[ServiceEnumTest("Bicycle")]item3,
[ServiceEnumTest("Car")]item4,
item5
}
Client side proxy generated code:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="ServiceEnum", Namespace="http://tempuri.org/")]
public enum ServiceEnum : int {
[System.Runtime.Serialization.EnumMemberAttribute()]
item1 = 0,
[System.Runtime.Serialization.EnumMemberAttribute()]
item2 = 1,
[System.Runtime.Serialization.EnumMemberAttribute()]
item3 = 2,
[System.Runtime.Serialization.EnumMemberAttribute()]
item4 = 3,
[System.Runtime.Serialization.EnumMemberAttribute()]
item5 = 4,
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
属性是一种语言功能,并且没有标准方法在 SOAP 消息中表示它们。所以你正在尝试的是不可能的。相反,您可以将类型添加为属性,或编写 自定义序列化程序< /a> 它将 .NET 属性值移动到 XML 属性,但这不会是可移植的 - 如果不做大量工作,它就不会在另一侧恢复。
Attributes are a language feature, and there's no standard way to represent them in a SOAP message. So what you're trying is impossible. You could, instead, add the type as an attribute, or write a custom serialiser which moves the .NET attribute value to an XML attribute, but that's not going to be portable - it won't hydrate back on the other side without a lot of work.