﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Web Services Software Factory (2 of 5)</title>
	<atom:link href="http://www.peteonsoftware.com/index.php/2008/05/27/web-services-software-factory-2-of-5/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peteonsoftware.com/index.php/2008/05/27/web-services-software-factory-2-of-5/</link>
	<description></description>
	<lastBuildDate>Tue, 16 Aug 2011 14:45:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Pete</title>
		<link>http://www.peteonsoftware.com/index.php/2008/05/27/web-services-software-factory-2-of-5/comment-page-1/#comment-2718</link>
		<dc:creator>Pete</dc:creator>
		<pubDate>Sat, 16 Jan 2010 19:33:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.peteonsoftware.com/?p=20#comment-2718</guid>
		<description>I use the data contract collection most often.  When it gets to the client, it is either a List or an array (you configure that in properties) and can be treated as such.  So, you would make a translator from the List of entities to the data contract collection and then return that collection.</description>
		<content:encoded><![CDATA[<p>I use the data contract collection most often.  When it gets to the client, it is either a List or an array (you configure that in properties) and can be treated as such.  So, you would make a translator from the List of entities to the data contract collection and then return that collection.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darko</title>
		<link>http://www.peteonsoftware.com/index.php/2008/05/27/web-services-software-factory-2-of-5/comment-page-1/#comment-2717</link>
		<dc:creator>Darko</dc:creator>
		<pubDate>Sat, 16 Jan 2010 19:15:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.peteonsoftware.com/?p=20#comment-2717</guid>
		<description>Okay, i got the GetPlayer working, pretty straightforward actually, dont know how i missed it.

About the data:
i should use the Data Contract Collection to send the data back to the client? Or just use arrays and make a translator like the one for HoleData?

Thank you, you&#039;ve been really helpful!</description>
		<content:encoded><![CDATA[<p>Okay, i got the GetPlayer working, pretty straightforward actually, dont know how i missed it.</p>
<p>About the data:<br />
i should use the Data Contract Collection to send the data back to the client? Or just use arrays and make a translator like the one for HoleData?</p>
<p>Thank you, you&#8217;ve been really helpful!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete</title>
		<link>http://www.peteonsoftware.com/index.php/2008/05/27/web-services-software-factory-2-of-5/comment-page-1/#comment-2716</link>
		<dc:creator>Pete</dc:creator>
		<pubDate>Sat, 16 Jan 2010 18:50:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.peteonsoftware.com/?p=20#comment-2716</guid>
		<description>Darko,

The issue is that your GetPlayer method of your businessLogic class is returning entities.  You need to call the entity to contract translator on the results of that method before assigning it to response.PlayerPartResponse.

Using this style, it isn&#039;t uncommon to have to translate coming in from the request and then have to translate back to send a response.

It is generally considered bad to return a dataset from a service.  A common set of steps would look like this:
1. Request comes in with an id or search string, etc
2. Pass these (usually simple objects - string, int, etc) to the logic layer for validation.  If they are complex objects themselves, they need translated from contract to entity before passing to Logic Layer.
3. Logic validations are performed by logic layer and parameters are passed in some form to the data access layer
4. Data access layer takes those parameters and through your chosen means (ado.net, linq to sql, nHibernate, etc) gets the data and creates business objects, passing them back to the logic layer.
5. Logic layer may or may not perform validations on these objects and then passes them back to the original calling layer.
6. Service implementation layer takes this business object or collection of business objects and translates them into data contracts, which are then assigned into the response object and returned back to the service&#039;s caller.

If you are still having problems, you could always zip your code and email it to me at peter [dot] shearer [at] gmail [dot] com or put it in a public source repository and I can take a look at it and see if I can spot the problems.</description>
		<content:encoded><![CDATA[<p>Darko,</p>
<p>The issue is that your GetPlayer method of your businessLogic class is returning entities.  You need to call the entity to contract translator on the results of that method before assigning it to response.PlayerPartResponse.</p>
<p>Using this style, it isn&#8217;t uncommon to have to translate coming in from the request and then have to translate back to send a response.</p>
<p>It is generally considered bad to return a dataset from a service.  A common set of steps would look like this:<br />
1. Request comes in with an id or search string, etc<br />
2. Pass these (usually simple objects &#8211; string, int, etc) to the logic layer for validation.  If they are complex objects themselves, they need translated from contract to entity before passing to Logic Layer.<br />
3. Logic validations are performed by logic layer and parameters are passed in some form to the data access layer<br />
4. Data access layer takes those parameters and through your chosen means (ado.net, linq to sql, nHibernate, etc) gets the data and creates business objects, passing them back to the logic layer.<br />
5. Logic layer may or may not perform validations on these objects and then passes them back to the original calling layer.<br />
6. Service implementation layer takes this business object or collection of business objects and translates them into data contracts, which are then assigned into the response object and returned back to the service&#8217;s caller.</p>
<p>If you are still having problems, you could always zip your code and email it to me at peter [dot] shearer [at] gmail [dot] com or put it in a public source repository and I can take a look at it and see if I can spot the problems.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darko</title>
		<link>http://www.peteonsoftware.com/index.php/2008/05/27/web-services-software-factory-2-of-5/comment-page-1/#comment-2715</link>
		<dc:creator>Darko</dc:creator>
		<pubDate>Sat, 16 Jan 2010 17:21:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.peteonsoftware.com/?p=20#comment-2715</guid>
		<description>Hello again.

I have another problem with my project. Working with strings is fine, but i get problems when i try to work with more complex types. For example, i would like my service to return a list of all players in the database. How do i aproach that? Can i just return a DataSet back to the client app? If so, how?

Even when trying to return a &quot;Player&quot; type, i get problems.

in the GolfImplementation.cs, where im supposed to call the translators, i have this code:

GetPlayerResponse response = new GetPlayerResponse(); 
response.PlayerPartResponse = businessLogic.GetPlayer(PlayerTranslator.TranslatePlayerToPlayer(request.PlayerPart));
return response;

GetPlayer method in the GolfBusinessLogic.cs is a &quot;Player&quot; type, and so is the one in GolfManager.cs, because i assumed im supposed to return a Player type back to the client app. Anyhow, i keep getting the &quot;Cannot implicitly convert BusinessEntities.Player to DataContracts.Player&quot; error in the code above and i cant get arround it. The Translator works only with strings and a integer, so that cant be the reason.

Sorry for bothering you with this, i know it&#039;s getting a bit out of the whole Service Factory topic so i&#039;d really appreciate your help!

Cheers!</description>
		<content:encoded><![CDATA[<p>Hello again.</p>
<p>I have another problem with my project. Working with strings is fine, but i get problems when i try to work with more complex types. For example, i would like my service to return a list of all players in the database. How do i aproach that? Can i just return a DataSet back to the client app? If so, how?</p>
<p>Even when trying to return a &#8220;Player&#8221; type, i get problems.</p>
<p>in the GolfImplementation.cs, where im supposed to call the translators, i have this code:</p>
<p>GetPlayerResponse response = new GetPlayerResponse();<br />
response.PlayerPartResponse = businessLogic.GetPlayer(PlayerTranslator.TranslatePlayerToPlayer(request.PlayerPart));<br />
return response;</p>
<p>GetPlayer method in the GolfBusinessLogic.cs is a &#8220;Player&#8221; type, and so is the one in GolfManager.cs, because i assumed im supposed to return a Player type back to the client app. Anyhow, i keep getting the &#8220;Cannot implicitly convert BusinessEntities.Player to DataContracts.Player&#8221; error in the code above and i cant get arround it. The Translator works only with strings and a integer, so that cant be the reason.</p>
<p>Sorry for bothering you with this, i know it&#8217;s getting a bit out of the whole Service Factory topic so i&#8217;d really appreciate your help!</p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darko</title>
		<link>http://www.peteonsoftware.com/index.php/2008/05/27/web-services-software-factory-2-of-5/comment-page-1/#comment-2714</link>
		<dc:creator>Darko</dc:creator>
		<pubDate>Fri, 15 Jan 2010 14:35:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.peteonsoftware.com/?p=20#comment-2714</guid>
		<description>Thank you for the quick reply.

I did everything you said ( hopefully it&#039;s correct ), made the HoleData translator and all the methods. So far so good. Everything compiled like it should and when i finish the rest of the code, i&#039;ll give it a try.. Shouldn&#039;t be difficult from now on since i know what the problem was.

Thanks for your help!</description>
		<content:encoded><![CDATA[<p>Thank you for the quick reply.</p>
<p>I did everything you said ( hopefully it&#8217;s correct ), made the HoleData translator and all the methods. So far so good. Everything compiled like it should and when i finish the rest of the code, i&#8217;ll give it a try.. Shouldn&#8217;t be difficult from now on since i know what the problem was.</p>
<p>Thanks for your help!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete</title>
		<link>http://www.peteonsoftware.com/index.php/2008/05/27/web-services-software-factory-2-of-5/comment-page-1/#comment-2713</link>
		<dc:creator>Pete</dc:creator>
		<pubDate>Fri, 15 Jan 2010 12:58:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.peteonsoftware.com/?p=20#comment-2713</guid>
		<description>Darko,

You need to create a HoleData translator class and then call that from within your Course translator class.  Inside that HoleData translator, create 4 static methods: TranslateToEntity (takes a contract and returns an Entity), TranslateToContract (takes an Entity and returns a Contract), TranslateToEntities (takes an array of contracts and returns an array of Entities), and TranslateToContracts (takes an array of Entities and returns an array of Contracts).


The issue is one of the C# language.  You can map simple types from one namespace to another without casting, but complex objects or collections need cast.  


So inside the Course Translator, you would call the HoleData translator like this:

// assume I have a Course Contract Object foo 
// and a Course Entity Object bar
foo.HoleData = HoleDataTranslator.TranslateToContracts(bar.HoleData);

Meanwhile, over in the HoleDataTranslator, you could implement the TranslateToContract method exactly like in my examples for each property of HoleData.  For the TranslateToContracts method, you could then call it either like:
// Assuming a HoleData Entity Object of goog
var bing = new DataContract.HoleData[goog.Length];
for (var i = 0; i &lt; goog.Length; i++)
{
    bing[i] = TranslateToContract(goog[i]);
} 
return bing;

or in a shorter way available in .Net 3.5/C# 3
// I usually use generic lists for collections
// because of methods like ConvertAll which are
// very easy to use
return goog.ToList().ConvertAll(g =&gt; TranslateToContract(g)).ToArray();

There is a lot there, but hopefully I&#039;ve gotten you on the right track.  The main thing to remember is that you need a new translator (HoleDataTranslator), whose static methods will be called from within the CourseTranslator to map those properties you are having trouble with.

Happy Coding.</description>
		<content:encoded><![CDATA[<p>Darko,</p>
<p>You need to create a HoleData translator class and then call that from within your Course translator class.  Inside that HoleData translator, create 4 static methods: TranslateToEntity (takes a contract and returns an Entity), TranslateToContract (takes an Entity and returns a Contract), TranslateToEntities (takes an array of contracts and returns an array of Entities), and TranslateToContracts (takes an array of Entities and returns an array of Contracts).</p>
<p>The issue is one of the C# language.  You can map simple types from one namespace to another without casting, but complex objects or collections need cast.  </p>
<p>So inside the Course Translator, you would call the HoleData translator like this:</p>
<p>// assume I have a Course Contract Object foo<br />
// and a Course Entity Object bar<br />
foo.HoleData = HoleDataTranslator.TranslateToContracts(bar.HoleData);</p>
<p>Meanwhile, over in the HoleDataTranslator, you could implement the TranslateToContract method exactly like in my examples for each property of HoleData.  For the TranslateToContracts method, you could then call it either like:<br />
// Assuming a HoleData Entity Object of goog<br />
var bing = new DataContract.HoleData[goog.Length];<br />
for (var i = 0; i < goog.Length; i++)<br />
{<br />
    bing[i] = TranslateToContract(goog[i]);<br />
}<br />
return bing;</p>
<p>or in a shorter way available in .Net 3.5/C# 3<br />
// I usually use generic lists for collections<br />
// because of methods like ConvertAll which are<br />
// very easy to use<br />
return goog.ToList().ConvertAll(g => TranslateToContract(g)).ToArray();</p>
<p>There is a lot there, but hopefully I&#8217;ve gotten you on the right track.  The main thing to remember is that you need a new translator (HoleDataTranslator), whose static methods will be called from within the CourseTranslator to map those properties you are having trouble with.</p>
<p>Happy Coding.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darko</title>
		<link>http://www.peteonsoftware.com/index.php/2008/05/27/web-services-software-factory-2-of-5/comment-page-1/#comment-2712</link>
		<dc:creator>Darko</dc:creator>
		<pubDate>Fri, 15 Jan 2010 11:52:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.peteonsoftware.com/?p=20#comment-2712</guid>
		<description>Hi.

I need some help with these translators. Im using the Service Factory to make a Golfing service ( for school ), and i have a problem.

So, i have golf courses, and each golf course has 9 or 18 holes. In the Data Contract Model, i have a Data Contract for courses ( Name, Par, CourseRating, etc. ) and one for holes ( HoleNo, Distance, Handicap, etc. ). All i want, is for the Course class to have an array of HoleData objects, and the problem is i dont know how o properly connect these two contracts.
I tried setting the collection type of the HoleData member that appears in the Course contrat, but no matter what i do, when i try to generate the translator and to map the DataContracts.Course HoleData(HoleData[]) with the BusinessEntities.Course HoleData(HoleData[]) i get an &quot;Invalid Property Mapping&quot; error, saying it can&#039;t map, and possible reasons being incopatible types or unavailable getter/setter pairs.

I hope you understood my problem, and you can help me fix this problem.
And thank you for the tutorial, it helped a lot!

Cheers!</description>
		<content:encoded><![CDATA[<p>Hi.</p>
<p>I need some help with these translators. Im using the Service Factory to make a Golfing service ( for school ), and i have a problem.</p>
<p>So, i have golf courses, and each golf course has 9 or 18 holes. In the Data Contract Model, i have a Data Contract for courses ( Name, Par, CourseRating, etc. ) and one for holes ( HoleNo, Distance, Handicap, etc. ). All i want, is for the Course class to have an array of HoleData objects, and the problem is i dont know how o properly connect these two contracts.<br />
I tried setting the collection type of the HoleData member that appears in the Course contrat, but no matter what i do, when i try to generate the translator and to map the DataContracts.Course HoleData(HoleData[]) with the BusinessEntities.Course HoleData(HoleData[]) i get an &#8220;Invalid Property Mapping&#8221; error, saying it can&#8217;t map, and possible reasons being incopatible types or unavailable getter/setter pairs.</p>
<p>I hope you understood my problem, and you can help me fix this problem.<br />
And thank you for the tutorial, it helped a lot!</p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: liliana</title>
		<link>http://www.peteonsoftware.com/index.php/2008/05/27/web-services-software-factory-2-of-5/comment-page-1/#comment-2405</link>
		<dc:creator>liliana</dc:creator>
		<pubDate>Mon, 07 Sep 2009 21:42:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.peteonsoftware.com/?p=20#comment-2405</guid>
		<description>ok =] ill be waiting for your examples, im totally new to this wssf thing so i get confused haha but thanks for your answer =]</description>
		<content:encoded><![CDATA[<p>ok =] ill be waiting for your examples, im totally new to this wssf thing so i get confused haha but thanks for your answer =]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete</title>
		<link>http://www.peteonsoftware.com/index.php/2008/05/27/web-services-software-factory-2-of-5/comment-page-1/#comment-2404</link>
		<dc:creator>Pete</dc:creator>
		<pubDate>Mon, 07 Sep 2009 18:36:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.peteonsoftware.com/?p=20#comment-2404</guid>
		<description>liliana,

Your data contracts are strictly for what will be sent back from the service to the caller.  Your business entities are what any ORM tool would be mapping (LINQ to Sql included).  You have LINQ fetch your data into its entities (which will most often look like your DB), and then you use the translators to map what properties of your LINQ entities map to what properties of your data contracts.


I&#039;ve had several requests to get the source of this tutorial up and online, so maybe I&#039;ll see if I can find it (or just redo the tutorial myself) and maybe I&#039;ll make a LINQ to Sql version as well.</description>
		<content:encoded><![CDATA[<p>liliana,</p>
<p>Your data contracts are strictly for what will be sent back from the service to the caller.  Your business entities are what any ORM tool would be mapping (LINQ to Sql included).  You have LINQ fetch your data into its entities (which will most often look like your DB), and then you use the translators to map what properties of your LINQ entities map to what properties of your data contracts.</p>
<p>I&#8217;ve had several requests to get the source of this tutorial up and online, so maybe I&#8217;ll see if I can find it (or just redo the tutorial myself) and maybe I&#8217;ll make a LINQ to Sql version as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: liliana</title>
		<link>http://www.peteonsoftware.com/index.php/2008/05/27/web-services-software-factory-2-of-5/comment-page-1/#comment-2403</link>
		<dc:creator>liliana</dc:creator>
		<pubDate>Mon, 07 Sep 2009 16:38:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.peteonsoftware.com/?p=20#comment-2403</guid>
		<description>hi, i need to do it with a linq connection, do i have to use data contract in the data contract tools?, and the values have to be the same as my db table?
its hard to find a web service factory example with wcf and linq, do you know where i can find any examples?
thank youuuuu =D</description>
		<content:encoded><![CDATA[<p>hi, i need to do it with a linq connection, do i have to use data contract in the data contract tools?, and the values have to be the same as my db table?<br />
its hard to find a web service factory example with wcf and linq, do you know where i can find any examples?<br />
thank youuuuu =D</p>
]]></content:encoded>
	</item>
</channel>
</rss>

