开发者

Making an interface visible across WCF web services

开发者 https://www.devze.com 2023-03-19 01:42 出处:网络
I would like to declare an interface in my Web Service layer and then have the caller create objects of this interface type via proxy and use them to call the service methods.

I would like to declare an interface in my Web Service layer and then have the caller create objects of this interface type via proxy and use them to call the service methods. However, when I decorate the interface with DataContract attribute, I get an error saying this attribute can only be applied to class, struct and enum. I don't think that ServiceContract attribute makes sense, as the interface I am trying to expose is used only for data transfer purposes. I also noticed that when the interface was decorated with ServiceContract, it wasn't displayed in the proxy class created. What is the best practice开发者_JAVA百科 to go about this?


You cannot do that. "DataContract" interface cannot be exposed as part of metadata. Also even if you share the interface (in assembly) your clients will not be able to send their implementation back to your service because receiving side needs real type for deserialized instance.


The service contract is used on the interface, that is the name of the services. The data contract is used on the class, the data that you are sending over.

  • ServiceContract on the interface
  • OperationContract on the methods
  • DataContract on Class
  • DataMember on properties

See: http://msdn.microsoft.com/en-us/magazine/cc163647.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号