我的项目中有两个 WCF 服务。服务共享一种类型,但每个服务都生成自己的类型。是否可以为两种服务生成一个类?
服务器端的示例代码:
[DataContract]
class MyClass { /*some properties*/ }
[ServiceContract]
public interface IService1
{
[OperationContract]
MyClass GetSomeValue();
}
public class Service1 : IService1
{
public MyClass GetSomeValue() { /*some logic*/ }
}
[ServiceContract]
public interface IService2
{
[OperationContract]
MyClass GetSomeOtherValue();
}
public class Service2 : IService2
{
public MyClass GetSomeOtherValue() { /*some logic*/ }
}
在客户端,为每个服务生成两个“MyClass”:
namespace Services.Service1Reference {
[System.SerializableAttribute()]
public partial class RSTRole : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged
{
}
和
namespace Services.Service2Reference {
[System.SerializableAttribute()]
public partial class RSTRole : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged
{
}