我当前的设置是一个 ASMX
Web 服务,它有一个 Item
对象,并返回 Items
的 List
代码>.
Item
有 114 个各种类型的字段。它由 .NET Web 应用程序以及 Java Web 应用程序(使用 Axis2 生成客户端代理)使用。
我的问题是,每次我们想要向结果集中添加一个字段时,我们都必须修改服务以将该字段添加到对象中,并为java端生成一个新的客户端代理。此外,将 sql 字段映射到对象字段是一种大型方法,将每个字段从数据读取器加载到对象中,确保转换为正确的数据类型。
有没有更动态的方法来做到这一点?我查看了字典列表,但无法序列化。另一种方法是发送带有 Key
和 Value
字段的 Struct
的 List
。现在,这将解析类型的工作转移到客户端上,这不一定是最佳的。
是否有一种模式可以处理这样的事情,或者除此之外,是否有人有一个好的解决方案来帮助使其更易于维护?如果我们的 Java 应用程序有一种不错的方式来使用该服务,我愿意将其转换为 WCF(尽管我对 WCF 不太熟悉)。
如果您需要更多详细信息,请询问。谢谢!
My current set up is an ASMX
web service that has an Item
object, and returns a List<>
of Items
.
Item
has 114 fields of various types. It is consumed by .NET web apps, as well as Java web apps (using Axis2 to generate a client proxy).
My problem is that every time we want to add a field to the result set, we have to modify the service to add the field to the object, as well as generate a new client proxy for the java side. Also, the mapping of the sql fields to the object fields is one large method loading each field from the datareader into the object, making sure to convert to the proper datatype.
Is there a more dynamic way to do this? I looked into a list of Dictionary, but that cannot be serialized. An alternative is to send a List<>
of Struct
with Key
and Value
fields. This now puts the effort of parsing the types onto the client, which isn't necessarily optimal.
Is there a pattern that handles something like this, or barring that, does anyone have a good solution to help make this a little more maintainable? I'm open to converting it to WCF (though I am not too familiar with WCF) if there is a decent way for our Java apps to consume the service.
If you need more details, just ask. Thanks!
发布评论
评论(1)
除了使用
List>
之类的东西之外,我认为您不会找到任何其他解决方案; WCF 在这方面不会有太大帮助。我认为这实际上是一个很好的解决方案,它将使数据的读取变得更加简单和可扩展,并且在添加新字段时不需要对服务器端代码进行太多更改。
您可以在客户端上编写代码来完成将值对映射回真实结构的工作,然后大部分代码更改(添加字段时)都会与您的客户端隔离。此外,如果您的客户不需要新字段,您可以忽略更改而不会破坏任何内容。
Outside of using something like a
List<KeyValuePair<string, object>>
I don't think you're going to find any other solution; WCF isn't going to help much in that respect.I think that's actually a good solution, it will make the reading of your data much simpler and scalable, and you wouldn't need to change your server side code much when you add new fields.
You could write code on the clients that do the work of mapping the value pairs back to a real structure, and then most of the code changes (when a field is added) is isolated to your clients. Also, if your clients don't need the new fields, you can just ignore the changes without breaking anything.