5

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?

Nirmit Shah
  • 758
  • 4
  • 10

2 Answers2

1

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.

tom redfern
  • 30,562
  • 14
  • 91
  • 126
  • /r flag in svcutil is useful for me. However, for each integration, there are around 500 classes being generated. So its not possible for me to change these many classes manually. Also, it is not recommended to modify auto-generated classes. – Nirmit Shah May 19 '11 at 00:24
  • I would agree it's not wise to modify generated files if the source contracts changed often. However as you are calling an Oracle service I don't expect this to be the case. So it's safe to do so. It's a one-off exercise so while it may be time consuming, once it's done it's done. I don't know what other solution to suggest. – tom redfern May 20 '11 at 15:06
0

Use XSD2Code - you can specify the target namespace of the generated c# class.

Sascha
  • 2,193
  • 3
  • 24
  • 38
  • problem with xsd2code is that it generates all the classes in a same namespace. My requirement is to generate classes with namespace as XSD namespace. – Nirmit Shah May 16 '11 at 00:26