Exchange a DataContract between HOST and CLIENT - WCF

Posted on 2011-10-05
Last Modified: 2012-05-12

I have a service method like below:


<OperationContract()> _
Function AddFunc(ByVal value1 As Integer, ByVal value2 As Integer) As Integer


<DataContract()> _
Public Class Person
    Private UserNameStr As String
    Private PasswordStr As String
    <DataMember()> _
    Public Property UserName() As String
            Return UserNameStr
        End Get
        Set(ByVal value As String)
            UserNameStr = value
        End Set
    End Property
    <DataMember()> _
    Public Property Password() As String
            Return PasswordStr
        End Get
        Set(ByVal value As String)
            PasswordStr = value
        End Set
    End Property
End Class


Public Function AddFunc(ByVal value1 As Integer, ByVal value2 As Integer) As Integer Implements IAdd.AddFunc
          AddFunc = value1 + value2
          ' Accessing the PERSON object here
End Function

So my PERSON object is neither parameter to "AddFunc" function nor its return type. But I want this object to be available on CLIENT side when PROXY (AddProxy) was created. I am getting PROXY by adding service reference. Let me know is there any way that i can access this object at client side !


Sub Main()
        Using client As New AddProxy.AddClient
            Dim objPerson As New AddProxy.Person  'Error here (I cannot access Person class here as AddProxy.Person is NOT available)
            objPerson.UserName = "Mike"
            objPerson.Password = "Sam"
        End Using
End Sub

Question by:milani_lucie
    1 Comment
    LVL 83

    Accepted Solution

    One option is to add a third dummy parameter of type person. You can make the parameter optional so your existing code would not need changing.

    Another option is to add the parameter, generate the proxies and then remove the parameter and change proxy class manually.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now