Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF Service Sharing Types
    primarykey
    data
    text
    <p>I am writing a WCF service and code to consume it and I want to share data types between these services. </p> <p>I have a WCF library with the types I want to share defined in it. My WCF service and my WCF client both reference the assembly from the library. Classes look like this:</p> <pre><code>&lt;DataContract()&gt; _ Public Class MyEntity Private _culture As String = String.Empty Private _name As String = String.Empty &lt;DataMember()&gt; _ Public Property ID As Integer Get Return _id End Get Set(ByVal Value As Integer) _id = Value End Set End Property &lt;DataMember()&gt; _ Public Property Name() As String Get Return _name End Get Set(ByVal Value As String) _name = Value End Set End Property End Class </code></pre> <p>What I would like to do in my consuming application is create an instance of MyEntity and assign it's value to the return value of a method in my service that, naturally , returns an instance of MyEntity.</p> <p>So when I add a reference to my service from my client and give the service namespace the name "MyWCF" I would like to something like:</p> <pre><code>Dim entity as new MyEntity dim srv as new MyWCF.MyServiceClient entity = srv.MyMethod() </code></pre> <p>Right now when I do this the compiler gives me an error because it cannot implicitly convert type myclientnamespace.MySCF.Myclass to myclientnamespace.MyClass. I have read the posts <a href="https://stackoverflow.com/questions/2037182/problem-with-wcf-and-multiple-namespaces-sharing-object-types-across-multiple">here</a> and the article <a href="http://blog.walteralmeida.com/2010/08/wcf-tips-and-tricks-share-types-between-server-and-client.html" rel="nofollow noreferrer">here</a> - which was referenced in another stackoverflow thread. These state that if my client code is referencing the same assembly as my service code and I have that assembly reference in <strong>before</strong> I create the service reference the client code should <strong>not</strong> create proxy classes and rather use the classes in the referenced entity assembly. I have tried this and it is not working. I even made sure that the "Reuse types in all referenced assemblies" radio button is checked when I create the service reference. </p> <p>My questions are :</p> <p><strong>Can anyone see what I am doing wrong here? Should creating the service reference after the entities assembly reference was made not result in reusing the types?</strong></p> <p><strong>Is it possible to reuse types in this fashion?</strong></p> <p>Any advice would be very much appreciated. Thanks! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload