Monday, 17 December 2012

Forcing WCF generated proxies to share POJO's

We had a recent problem at work that seemed quite tough to solve, we have multiple SOAP endpoints exposed from a Java Enterprise Edition (JEE) container. The services were generated from Java code using Axis2. The services shared many POJOs.

We wanted to consume these services in a .NET client, client proxies were generated in the standard manner but this caused an issue. We ended up with the same POJO objects converted into multiple POCO's in different namespaces on the client.

I was resorting to svcutil without any success until I tried the following approach.




Open the Reference.Svc file and add multiple endpoints to one service definition.
  <MetadataSources>  
   <MetadataSource Address="http://mycompany.com/BananaService?wsdl" Protocol="http" SourceId="1" />  
   <MetadataSource Address="http://mycompany.com/OrangeService?wsdl" Protocol="http" SourceId="2" />  
   <MetadataSource Address="http://mycompany.com/AppleService?wsdl" Protocol="http" SourceId="3" />  
   ...  
  </MetadataSources>  
  <Metadata>  
   <MetadataFile FileName="BananaService.xsd" MetadataType="Schema" ...  
   <MetadataFile FileName="BananaService.wsdl" MetadataType="Wsdl" ...  
   <MetadataFile FileName="OrangeService.xsd" MetadataType="Schema" ...  
   <MetadataFile FileName="OrangeService.wsdl" MetadataType="Wsdl" ...  
   <MetadataFile FileName="AppleService.wsdl" MetadataType="Wsdl" ...  
   <MetadataFile FileName="AppleService.xsd" MetadataType="Schema" ...  
   ...  
  </Metadata>  



Now 'Update the service Reference', and bingo one C# source file with all client proxies in in one namespace all sharing the same POCOS!

No comments:

Post a Comment