none
Same class in different assemblies RRS feed

  • Question

  • Hi there

    I created a couple of service references in my project: My.LoginServiceReference and My.DictionaryServiceReference. Both uses the SecurityDTO class instance. If I call

    DictionaryServiceReference.DictionaryServiceClient wc = new DictionaryServiceReference.DictionaryServiceClient();
    wc.GetDictionaries(IDTWebUserClass.Get().Security, out errorStr);

    System does not like the IDTWebUserClass.Get().Security cause it is from the My.LoginServiceReference, but it expects from the My.DictionaryServiceReference.

    How to say the System that the SecurityDTO  in that call is exactly the same as I have in My.DictionaryServiceReference?

    Or how to update my My.LoginServiceReference and My.DictionaryServiceReference (WCF) so as the SecurityDTO  gets the same namespace?

    Thanks.

    Friday, January 12, 2018 2:46 PM

All replies

  • Unfortunately this is an issue with service references. On the actual client-server call then the types don't matter as they get serialized to SOAP and back. But while in .NET, trying to use different types won't work because the CLR sees each type as unique irrelevant of name or members. 

    The correct workaround for service references depends upon how you're using them. If you need the same reference in 2 different projects and you want the projects to share the data then move the service reference (and its data structures) into a shared project. Then reference the shared project in both projects. Since there is only 1 implementation the separate projects can communicate.

    If the data itself is already defined in a stand alone assembly but the service reference wants to create it own version then configure the reference again and opt to use the shared assembly to help resolve types. This will cause the generator to only generate code for types it cannot find in the referenced assemblies. This is the default so it should already be doing this.


    Michael Taylor http://www.michaeltaylorp3.net

    Friday, January 12, 2018 2:59 PM
    Moderator
  • What you do is make a classlib project called Entities, and you pot the DTO there, The projects that need the DTO will set reference to Entities, and they will know what the DTO is about and there will be no issues.
    Friday, January 12, 2018 7:20 PM
  • IT IS a separate project using Silverlight namespaces and it works Ok in my Silverlight project providing many projects with DTO from the same namespace. But the problem is WCF. Another developer in another solution cannot consume my DTOs rather than from different namespaces.

    The solution must be somewhere in WCF namespace configuration.

    Thoughts?

    Monday, January 15, 2018 1:40 PM
  • "If the data itself is already defined in a stand alone assembly but the service reference wants to create it own version then configure the reference again and opt to use the shared assembly to help resolve types. This will cause the generator to only generate code for types it cannot find in the referenced assemblies. This is the default so it should already be doing this."

    Does this not solve your problem if the types are already defined in a separate assembly?


    Michael Taylor http://www.michaeltaylorp3.net

    Monday, January 15, 2018 5:25 PM
    Moderator
  • WCF wants a DTO to be marked as a DataContract() so it can travel between the WCF client and WCF service in a XML serialized format.

    Monday, January 15, 2018 5:41 PM