Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating DataContracts with exact namespace as in XSD

Tags:

c#

wsdl

xsd

wscf

We have to integrate our project with back end Oracle Platform. And this integration is via various WebServices. I have all WSDLs and XSDs for all these integrations. And I need to generate DataContracts from these WSDLs & XSDs.
Now the problem is, mostly all of these integration shares some common data types. and I want to reuse them.
e.g,

Integration1: oracle/common/commonDataTypes.xsd
              oracle/integration1/someXSD.xsd
              oracle/ebo/baseTypes.xsd
Integration2: oracle/common/commonDataTypes.xsd
              oracle/integration2/someXSD.xsd
              oracle/ebo/baseTypes.xsd
Integration3: oracle/commonDataTypes.xsd
              oracle/integration2/someXSD.xsd
              oracle/ebo/baseTypes.xsd

in this case, I want to reuse the oracle.common.CommonDataTypes between integration1 & 2.
so far I have tried WSCF.blue & WSCF. But these tools generating all the code in a single folder(and single namespace) and not following namespaces.
I want to generate classes under namespaces like oracle, oracle.commonData, oracle.integration1, oracle.ebo etc. so is that any way that generated Datacontracts follows exact namespace notation as the XSDs have?

like image 202
Nirmit Shah Avatar asked Nov 13 '22 23:11

Nirmit Shah


1 Answers

There is no tool which will do this for you I'm afraid. Or none that I know of. The best way to acheive what you want is:

  1. Extract the data contracts for integration 1 using the /dconly flag on svcutil. You need to include all the schema names in the call to svcutil. This will generate a class file with all the types.

  2. Go into the file and manually hack around until your classes are all in the right namespaces. Compile this into an assembly.

  3. Then go back to the integration 1 service and generate your proxy code using the /r flag in svcutil to reference your assembly containing your common types which you want to reuse. This will create a class file containing your proxy which should reference your common types.

  4. You can then do the same for integration 2 and 3.

However, this approach is based on svcutil using the DataContractSerializer to do the work, as the /r flag is not available to XmlSerializer. And this will only work if the schemas exposed on the oracle services adhere to the rather strict DCS rules (can be found here: http://msdn.microsoft.com/en-us/library/ms733112.aspx). If these rules are not adhered to then svcutil will fall back to using XmlSerializer which does not support reuse of types.

Hope this helps.

like image 194
tom redfern Avatar answered Dec 21 '22 23:12

tom redfern