0
我有一個WCF服務接口,看起來像這樣:WCF序列化 - 即時轉換爲不同類型?
[ServiceContract(Namespace = "http://somenamespace", SessionMode = SessionMode.NotAllowed)]
public interface IRuntimeService
{
[OperationContract]
ISupporterProperties CreateOrModifySupporter(Guid id);
}
和實現(客戶端和服務器上)看起來像這樣(其託管並連接到編程):
public IOwnerProperties CreateOrModifyOwner(Guid id)
{
//get an owner ...
//the owner is of type Owner which implements IOwnerProperties.
return theOwner;
}
但是,問題在於WCF會嘗試將此序列化或反序列化爲Owner
,因爲這是返回的實際類型,但我希望它將其作爲OwnerDataContract
發送,這也正好實現IOwnerProperties
。
換句話說,我想返回一個Owner
,但將它序列化/反序列化爲OwnerDataContract
。
我知道我可以爲客戶端界面創建包裝類。但是,我希望儘可能多地使用共享代碼。
這很有趣。有沒有使用第三方工具的方法? –
是的,但是那會讓你說你不想做的「爆炸班」。 Automapper通過'Mapper.CreateMap'動態地生成這些包裝 –