Service Composition - Sharing Data Types?

Topics: General Discussion Forum
Mar 29, 2007 at 8:40 PM
Hi,

I have ran into problem developing a web service with messages conatining data types that sometimes "wrap" results of another web service.

Essentially I have a service (<WebServiceA>) with response mesage containing data type <EntityA>. <EntityA> is a complex data type which contains data type <EntityB>. <EntityB> is always obtained by calling a method of <WebServiceB>.

As specified by the guidance, I have DataTypes(DT), ServiceContract(SC), ServiceImplementation(SI), BusinessEntities(BE), BusinessLogic(BL) and DataAccess(DA) projects for each of the two web services.

According to the guidance, the Data Access layer of <WebServiceA> should contain the "service agent" to the <WebServiceB>, which is nice and good. The resulting proxy has its own namespace for the <EntityB>, so I end up the <WebServiceBProxy.EntityB> down in the DA project of the WebServiceA. How do I get it up through the layers? What should the type of the <EntityB> property of <BusinessEntityA> be? Do I reference WebServiceB.DataTypes everywhere, including WebServiceA.DT, WebServiceA.BE and WebServiceA.SI?

Hopefully this ins't too confusing...If anyone ran into this, please let me know how you addresses it - help will be much appreciated.

Apr 5, 2007 at 4:49 PM
I ran into the same problem and didn´t find a clean solution yet.

One possible solution might me to declare type B even in WebserviceA.DT and convert the datatype WebserviceBProxy.EntityB to WebserviceA.EntityB. The problem is, that you might easily run into some serious problems, when you need to change your Entities later on. Expecially when you use the Entity in a lot of Services.

A second solution might be to declare the Entities and Datacontracts in one single project and reference this assembly in all services.

But as i told you before... neither of the two offers a clean solution. Hopefully someone else found a clean solution and will let us know....
Apr 6, 2007 at 2:12 PM
Thank, Flo1973 - I made a little headway, so here's what I have so far:

Lets say the two services are Student and Class, each having a corresponding datatype. Class datatype has a list of Students.

I've defined an xsd for Student and xsd for Class, having Class.xsd import Student.xsd. Then generated the datatypes for both, ended up with Student.DataTypes.Student, Class.DataTypes.Class and Class.DataTypes.Student (similar to option one in your post). After generating the proxy to the Student service, I also have Class.DataAccess.StudentProxy.Student... I see three options:

1. Reference Student.DataTypes library in both Class.DataTypes and Class.DataAccess.StudentProxy, rip out generated classes and add "using Student.DataTypes" in both places. Then the datatype and the namespace is the same (Student.DataTypes.Student), and one can simply do an assignment in the Class.ServiceImplemntation when mapping Class from business entity to data type. Class.DataTypes.Student and Class.DataAccess.StudentProxy.Student do not exist any more. Trouble is, we're fererencing other services' libraries from a data access layer of a service...

2. Do not touch either of the generated classes and use a custom reflection-based mapper to copy properties from Class.DataAccess.StudentProxy.Student to Class.DataTypes.Student. Trouble is, now Student is defined in 3 places.

3. Only rip out generated Student classes from the Class.DataTypes and reference Student.DataTypes in Class.DataTypes. Use a custom reflection-based mapper to copy properties from Class.DataAccess.StudentProxy.Student to Student.DataTypes.Student. This way the Student entity is defined by only a single library and only DataTypes libraries of the service are dependent.

Please let me know if there's something I'm missing and which approach you'd prefer...
Thanks!
Apr 6, 2007 at 7:24 PM
http://blogs.msdn.com/sowmy/archive/2006/06/06/618877.aspx

Here is an interesting blog about using KnownTypes for data contracts in WCF.

I don't know if this applies to your situation, but it seems similar.
Apr 7, 2007 at 7:37 AM
Edited Apr 7, 2007 at 7:37 AM

sbillingsley wrote:
http://blogs.msdn.com/sowmy/archive/2006/06/06/618877.aspx

Here is an interesting blog about using KnownTypes for data contracts in WCF.

I don't know if this applies to your situation, but it seems similar.


Yes, very helpful in my opinion.

One can find some good examples even here:

http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&tabid=11