views:

303

answers:

5

Hello, and thank you for reading.

I am implementing a WCF Service based on a predefined specification (HR-XML 3.0). As such, I am starting with the schema, and working my way back to code. There are a number of large Schema documents (which import yet more Schema documents) related to my implementation, provided by this specification.

I am able to generate code using xsd.exe, by supplying the "main" and "supporting" xsd files as arguments. But there are several issues, and I am wondering if this is the right approach.

  • there are litterally hundreds of classes - the code file is half a meg in size
  • duplicate classes (ex. Type, Type1 - which both represent the same type)
  • there are classes declared as inheriting from a base class, but that base class is not generated/defined

I understand that there are limitations to the types of Schema supported by svcutil.exe/xsd.exe when targeting the DataContractSerializer and even XmlSerializer. My question is two-fold:

  1. Are code generation "issues" fairly common when dealing with larger, modular xsd files? Has anyone had success with generating data contracts from OAGIS or HR-XML schema?
  2. Given the above issues, are there better approaches to this task, avoiding generating code and working with concrete objects? Does it make better sence to read and compose a SOAP message directly, while still taking advantage of the rest of the WCF framework? I understand that I am loosing the convenience of working with .NET objects, and the framekwork-provided (de)serialization; given these losses, would it still be advantageous to base my Service on WCF? Is there some "middle ground" between working with .NET types and pure XML?

Thank you very much!

-Sasha Borodin DFWHC.org

A: 

Well, you could try and do something like this:

  • convert your XSD to C# code separately, using something like the xsd.exe tool from Microsoft, or something like Xsd2Code as a Visual Studio Plugin.

Xsd2Code in Visual Studio

  • once you have your C# classes, weed out any inconsistencies, duplications, and so forth
  • package everything up into a separate class library assembly

  • now, when generating your WCF service from the WSDL, either using Add Service Reference from Visual Studio or the svcutil.exe tool, reference that assembly with all the data classes. Doing so, WCF should skip re-creating the whole set of classes again, and use whatever is available in that data assembly

With this, you might be able to get this mess under control.

marc_s
Marc_s, thanks for your response. I will give Xsd2Code a try. On a more general level, is there an alternate programming approach which avoids code generation, while still utilizing other WCF framework components?
Sasha Borodin
@Sasha: no, not really - you have to create those client proxy classes and the types involved in WCF message serialization somehow. You can do it from scratch, by hand - not recommended though!
marc_s
@Sasha: you could program directly against the XML. That's a lot easier now with LINQ to XML.
John Saunders
Per feedback on the MSDN forum, an alternative is to "program at the wcf channel level, which means we can read message and compose response message directly. Please refer to this article"Service Channel-Level Programminghttp://msdn.microsoft.com/en-us/library/ms789029.aspx
Sasha Borodin
@Sasha: that might be feasible - in theory. I'm definitely not going to want to do that by all means....
marc_s
+1  A: 

Sasha, If you are going to use code generation, you likely should never start with the modular schemas. When you put a code generator against the modular schemas, you'll generate a class for all the common compoents in the HR-XML library and a good bit of the common components in OAGIS. You don't want this. HR-XML is distributed with standalone schemas, which are a better starting point. An even better starting point would be to create a flattened package xsd containing only the types brought in by the WSDL. If you use a couple standalone schemas, you are going to at least have some duplications among your generated code.

Chuck Allen
I have been working with the "standalone" schemas, but generating code from two or more obviously creates duplicate type definitions for the "shared" components. I will try to assimilate everything into one XSD, and see where that takes me. Thanks for your answer!
Sasha Borodin
A: 

@Sasha. Let me know which schemas you are using in your operations. It is pretty easy for me to create the flattened package I mentioned, which I can post for you.

Chuck Allen
Chuck,I'm using ProcessScreeningPackageOrder, AcknowledgeScreeningPackageOrder, CancelScreeningPackageOrder, and ConfirmBOD. I went through a somewhat tedious process of code generation of those separate documents, and then pulling out the common types into one code file.If you can flatten the schemas mentioned above, or provide some guidance on how you would create a flattened package, that would be invaluable.Thanks very much!-Sasha Borodin
Sasha Borodin
A: 

Hi Chuck, I am also facing the similar issue. I am using ProcessStaffingOrder. I am new for HR-Xml. Could you provide me the guidance how to generate class for the HR-xml schemas.

Thanks in advance! Anup

Anup Sinha
A: 

Chunk,Am kind of new to HRXML.Am having same problem can you please send me the class files in c# for SyncStaffingAssignment,SyncStaffingJobOrder,SyncInidcativeData,SyncOrganizatinChart and ConfirmBOD for each of the them.

Thanks in advance.

don_don