WCF and Shared Reference Library Between Client & Service

一笑奈何 提交于 2019-12-01 08:26:59

The bug which you report as existing in Reuse types from referenced assemblies option happens because by specifying re-use VS calls svcutil.exe under the hood with the /r flag.

However, svcutil.exe uses DataContractSerializer to help generate code and unfortunately this has a rather strict set of rules when it comes to parsing your service contracts.

So unless you service XSDs adhere to this set of rules svcutil.exe will switch to use the XmlSerializer, which doesn't support the /r flag (or re-use). Hence you will not be able to re-use types.

If you can reference the actual service contract types (via binary reference) this is a much better solution as you can do away with service references all together. You can also use WSCF.blue to generate your service contracts, as this has it's own custom serializer and supports re-use of types.

In my situation both WebService and WebApp referenced the same assembly containing domain entities. Naturally, each entity was decorated with DataContractAttribute but when generating a ServiceReference in WebApp using an endpoint exposed by the WebService the Reuse Type in Referenced Assemblies had been seemingly ignored by VS2012, which resulted in additional copies of the types in the local assembly. Then (after several hours of trial and error) I added a Namespace parameter to the ServiceContractAttribute of my interface in WebService. Once added, the reparsed ServiceReference started to reference my shared DataContract types as desired.

 [ServiceContract(Namespace="http://www.example.com/Demo.WebService/")]
 public interface IConfigurationService { ..methods here.. }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!