inutan
inutan

Reputation: 10888

WCF - Exposing parameterized constructor

I have a WCF DataContract called RecipientDto defined as:

[DataContract]
public class RecipientDto
{
    [DataMember]
    public string Name
    {
        get;
        private set;
    }

    [DataMember]
    public string EmailAddress
    {
        get;
        private set;
    }

    public RecipientDto(string name, string emailAddress)
    {
        Name = name;
        EmailAddress = emailAddress;
        //Initialize other property here
    }
}

I want to have constructor of RecipientDto being exposed to the client as it involve some basic initialization of other properties (not shown here).

Please guide how can I achieve this.

Thank you!

Upvotes: 2

Views: 1052

Answers (2)

Oliver Weichhold
Oliver Weichhold

Reputation: 10296

What you could do is the create a second source file for the RecipientDto class, that contains a second declaration of the class with the "partial" keyword. Add your constructor to it and include that file in your client project using Visual Studio's "Add Link" functionality available on the "Add existing item" dialog. If you only need that constructor on the client then just define that second source file directly in the client project.

Upvotes: 0

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364359

You cannot achieve that unless you share assembly with your DTOs between client and server. Metadata (WSDL + XSD) can describe only data transferred by DTO. They cannot describe any logic defined in DTO on service side.

Upvotes: 6

Related Questions