DCSIMG

 Subscribe in a reader

Reusing types in WCF - Guy kolbis
Sunday, June 08, 2008 4:35 PM kolbis

Reusing types in WCF

For those of you who ever wrote a web service (I guess most of you have), sharing types was an impossible mission. If you had defined a type in the server side (the web service side), when consuming it on the client side, the proxy generated for you contained the same type but under a different namespace. Do you know that problem?!

When WCF shipped, a new possibilities emerged. One can now share types and reuse them.

In order to do so, all you need to do is get into the "Configure Service Reference.."

image 

Now verify that the "Reuse types in all referenced assemblies" is checked.

image

By default it will be checked!

The only issue with this mechanism is the fact that Data Contracts (Interfaces) are not being shared! I do not know what is the reason, but in order to overcome this "Bug", you have to manually delete the contract from the generated proxy and replace it with the shared contarct.

kick it on DotNetKicks.com תגים:,

תוכן התגובה

# re: Reusing types in WCF

E.V כתב/ה

הי גיא,

זה לא באג זה בכוונה כך.

כך יוצרים אי צמידות.

הדבר שקול לחוזה שאתה חותם ורוצה העתק..

יש לזכור WCF תומך בגרסאות.

Monday, June 09, 2008 11:53 AM

# re: Reusing types in WCF

kolbis כתב/ה

מסכים חלקית.

WCF מאפשר לשתף טיפוסים אבל לא חוזים (Interfaces).

אתה יכול לומר בדיוק את זה על טיפוסים שכן נתמכים. כתבתי Post שמדבר כיצד לשבור SOA עם WCF וזהו חלק נוסף.

Monday, June 09, 2008 1:39 PM

# re: Reusing types in WCF

Roy Elimelech כתב/ה

I'm sorry but I must disagree.

I think that objects you use in your contracts should be used only as data containers for your application and not contain any logic. this way you need no other reference than the service's. these objects must be specifically designed to transfer data and must support the service's serialization format. Adding functionality and using it for other purposes could also cause you some trouble with the serialization and force you to use attributes or weird workarounds to enforce the serialization format.

Monday, June 09, 2008 9:04 PM

# re: Reusing types in WCF

guy כתב/ה

Logic??? You are right,

Logic should not and cannot be serialized. We are talking about interfaces (contracts). The data contracts are being serialized, but the service contract are not.

Tuesday, June 10, 2008 8:05 AM

# re: Reusing types in WCF

Jerovino כתב/ה

I have the same problem, but i can't overcome it.

I need more tips!!

Thursday, July 24, 2008 3:19 PM

# Reusing types in WCF

DotNetKicks.com כתב/ה

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Thursday, December 04, 2008 5:12 PM

# re: Reusing types in WCF

JohnOpincar כתב/ה

I'm not sure why, but one time I did not have to manually edit the file.  Every other time I did.  I think it may have to do with using a project reference instead of a regular one because that's the only difference I can think of.

Monday, May 04, 2009 8:31 PM

שלח תגובה

(שדה חובה) 
(שדה חובה) 
(אופציונלי)
(שדה חובה) 

Enter the numbers above: