简体   繁体   English

WCF代理类的派生接口

[英]Derive Interfaces for WCF Proxy Classes

Problem: 问题:

I have two (or more) classes which are very similar : The properties of one class are a subset of the properties of the other class. 我有两个(或多个) 非常相似的类 :一个类的属性是另一类的属性的子集。 More specifically, the property names and semantics are equal, but not necessarily their types. 更具体地说,属性名称和语义是相等的,但不一定是它们的类型。 However, if the types of a property with the same name differ, these types are again very similar (in the same sense). 但是,如果具有相同名称的属性的类型不同,则这些类型也将非常相似 (相同意义上)。

I want to derive common interfaces for all sets of similar classes so I can use instances of different classes in the same way. 我想为所有相似类的集合派生通用接口,以便可以以相同方式使用不同类的实例。

Since my classes have more than 100 properties, I would like to avoid to create the interfaces manually if that is possible by any chance. 由于我的课程有100多个属性,因此,如果可能的话,我想避免手动创建接口。

The interface should encompass the union of all property sets of all similar classes. 接口应包含所有相似类的所有属性集的并集。 (When a property is read, which doesn't exist for the specific object, null should be returned. When such an undefined property is set, nothing should happen.) So I guess an interface isn't really appropriate anymore, but rather a wrapper class or something different... (读取特定对象不存在的属性时,应返回null 。设置了此类未定义的属性时,将不发生任何事情。)因此,我猜接口真的不再合适,而是一个包装器类或其他...

Context: 内容:

I am using WCF to consume a Web Service ( CreateSalesOrder ). 我正在使用WCF消耗Web服务( CreateSalesOrder )。 The input message of the service requires an element of the XML schema type Request_SalesOrder consisting of children of other XSD types like Request_Item , Request_ShipToLocation , etc. 服务的输入消息需要XML模式类型Request_SalesOrder的元素,该元素由其他XSD类型的子元素组成,例如Request_ItemRequest_ShipToLocation等。

The output message carries an element of the schema type Response_SalesOrder which has similar child elements of the schema types Response_Item , Response_ShipToLocation , etc. and some additional elements, eg element PriceTotal of type Response_PriceTotal . 输出消息包含模式类型Response_SalesOrder的元素,该元素具有模式类型Response_ItemResponse_ShipToLocation等的类似子元素以及一些其他元素,例如Response_PriceTotal类型的元素PriceTotal

I want to build a UI for consuming the Web Service using ASP.Net MVC. 我想构建一个使用ASP.Net MVC使用Web服务的UI。 So I have a view rendering a form for creating the sales order. 因此,我有一个呈现用于创建销售订单的表单的视图。 After submitting the Web Service request the form fields have to be updated with the values from the Web Service response message. 提交Web服务请求后,必须使用Web服务响应消息中的值更新表单字段。

The form fields are bound to a view model which accesses the properties of the proxy classes. 表单字段绑定到访问代理类属性的视图模型。 When the form is submitted the view model has to update an instance of proxy class A, while, in case the form is rendered with the values from the response message, the view model reads from an instance of proxy class B. 提交表单时,视图模型必须更新代理类A的实例,而如果表单使用响应消息中的值来呈现,则视图模型将从代理类B的实例中读取。

我认为您是在谈论adpater设计模式,但我不知道如何避免手动编写该接口: http : //en.wikipedia.org/wiki/Adapter_pattern

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM