Reusing types in WCF

8 ביוני 2008

תגיות: ,
6 תגובות

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

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. (*) שדות חובה מסומנים

6 תגובות

  1. E.V9 ביוני 2008 ב 11:53

    הי גיא,
    זה לא באג זה בכוונה כך.
    כך יוצרים אי צמידות.
    הדבר שקול לחוזה שאתה חותם ורוצה העתק..
    יש לזכור WCF תומך בגרסאות.

    להגיב
  2. kolbis9 ביוני 2008 ב 13:39

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

    להגיב
  3. Roy Elimelech9 ביוני 2008 ב 21:04

    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.

    להגיב
  4. guy10 ביוני 2008 ב 8:05

    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.

    להגיב
  5. Jerovino24 ביולי 2008 ב 15:19

    I have the same problem, but i can't overcome it.
    I need more tips!!

    להגיב
  6. JohnOpincar4 במאי 2009 ב 20:31

    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.

    להגיב