Reputation: 493
Here's my basic scenario. I have three services. One is self-contained and mostly doesn't cause problems. The other two services are hosted in the same project and share nearly all of the same DataContracts. This means that included in the same project, they cause lots of conflicts.
Unfortunately, simply deleting the duplicate classes isn't an option, since my company is starting to automate our builds, and this needs to go in the pre-build events and use svcutil.exe.
I first tried adding an assembly called MyProject.DataContracts. Then, in the pre-build of MyProject.DataContracts, I would run this:
mkdir "$(ProjectDir)SVC"
chdir "$(ProjectDir)SVC"
svcutil /t:metadata http://localhost/Cmpny.FirstHost.ServiceHost/Foo.svc http://localhost/Cmpny.FirstHost.ServiceHost/Bar.svc http://localhost/Cmpny.StandaloneService.ServiceHost/Service.svc /r:"D:\TFSMAP\AssemblyReferences\Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.dll" /collectionType:System.Collections.Generic.List`1
svcutil /t:code /language:VB Cmpny.FirstHost.DataContracts*.xsd /serializer:DataContractSerializer /dcOnly /out:Cmpny.FirstHost.DataContracts /n:*,Contracts
svcutil /t:code /language:VB Cmpny.StandaloneService.DataContracts*.xsd /serializer:DataContractSerializer /dcOnly /out:Cmpny.StandaloneService.DataContracts /n:*,Contracts
copy Cmpny.StandaloneService.DataContracts.vb "$(ProjectDir)Service References"
copy Cmpny.FirstHost.DataContracts.vb "$(ProjectDir)Service References"
chdir "$(ProjectDir)"
rmdir /S /Q "$(ProjectDir)SVC"
This runs, replaces the files, and the builds the project with the new files. This part is working correctly, in that all the types output to the files, and show up in the assembly.
The next part is giving me trouble. I've added this to the Pre-Build event of the main project.
mkdir "$(ProjectDir)SVC"
chdir "$(ProjectDir)SVC"
svcutil /t:code http://localhost/Cmpny.FirstHost.ServiceHost/BusinessDataService.svc?singleWsdl /r:"$(SolutionDir)MyProject.DataContracts\bin\Release\MyProject.DataContracts.dll" /r:"$(SolutionDir)MyProject.DataContracts\bin\Release\Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.dll" /language:VB /out:BusinessDataService /collectionType:System.Collections.Generic.List`1
svcutil /t:code http://localhost/Cmpny.FirstHost.ServiceHost/PremiumReportingService.svc?singleWsdl /r:"$(SolutionDir)MyProject.DataContracts\bin\Release\MyProject.DataContracts.dll" /r:"$(SolutionDir)MyProject.DataContracts\bin\Release\Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.dll" /language:VB /out:PremiumReportingService /collectionType:System.Collections.Generic.List`1
svcutil /t:code http://localhost/Cmpny.StandaloneService.ServiceHost/Service.svc?singleWsdl /r:"$(SolutionDir)MyProject.DataContracts\bin\Release\MyProject.DataContracts.dll" /r:"$(SolutionDir)MyProject.DataContracts\bin\Release\Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.dll" /language:VB /out:PaymentService /collectionType:System.Collections.Generic.List`1 /et:"$(SolutionDir)MyProject.DataContracts\bin\Release\MyProject.DataContracts.dll"
copy BusinessDataService.vb "$(ProjectDir)Service References"
copy PremiumReportingService.vb "$(ProjectDir)Service References"
copy PaymentService.vb "$(ProjectDir)Service References"
chdir "$(ProjectDir)"
rmdir /S /Q "$(ProjectDir)SVC"
This process succeeds, however, it generates the DataContract types again, despite the fact that I've included the MyProject.DataContracts.dll. After this, I have three sets of DataContracts in my Project, the ones from Foo.svc, the ones from Bar.svc, and the ones in the DataContract file where they're supposed to be.
I've tried changing the clr namespace to the same as the DataContract namespace, but that doesn't work. It changes my method signatures as well and gives me a truly staggering amount of errors.
TL;DR; I need a common DataContract file for a service so I don't get duplicate DataContract types. I cannot seem to import my DataContract dll to svc properly, so it generates new DataContracts twice, one for each service, and once more in the original dll(where they're supposed to be).
Please let me know if anything is unclear, I've tried to be as descriptive as possible.
Upvotes: 1
Views: 58
Reputation: 493
I figured this out.
I set the serializer on the Contract files to the DataContractSerializer. For some reason it was defaulting to the XmlSerializer and therefore not recognizing the DataContracts as equivalent the the types it was creating.
I simply added the option '/serializer:DataContractSerializer' to the second build event that creates the DataContracts.
However, now I'm encountering another problem. Two of my Contracts aren't generating arguments for their methods.
Upvotes: 0