0

I have a custom type in my asp.net web service. I have parameterized constructor for the same type. But when I try to use the same type on client side I can only see the default constructor with no parameter. This is my type.

public class Task
{

    public string AssignedTo { get; set; }

    public int CallDuration { get; set; }

    public Task(string assignedTo,int callDuration)
    {
        AssignedTo = assignedTo;
        CallDuration = callDuration;
    }
}
Naresh
  • 2,667
  • 13
  • 44
  • 69

2 Answers2

0

I don't believe that SvcUtil (what VS uses when adding a service reference) will add it with the parameterized constructor.

What you can do instead, is put the class into a shared library that's added as a normal reference to both the server and client. When adding the service reference, reuse the types, and you can use your constructor because proxy types will not be created for reused types.

This is also useful if your types have helper methods you would like access to on the client.

Grant H.
  • 3,689
  • 2
  • 35
  • 53
  • Thanks for your reply. But I don't think it's better idea to use common libraries. I think if we have the feasibility of using common libraries then there is no point of going for web services. – Naresh Sep 19 '12 at 21:53
  • @Naresh, I'm talking about a library that only has the classes used to transfer data over the wire. You would certainly still need server side logic, necessitating web services. This is a routine practice for solving exactly the problem you described. Instead of letting SvcUtil generate proxy classes, you are just exposing those classes to the client so that it uses them instead of what would have been created during proxy generation. – Grant H. Sep 20 '12 at 12:05
0

Should work fine if you update the service reference on the client side. Not sure in a traditional web service, but in WCF the service needs to be running to do this.

KennyZ
  • 907
  • 5
  • 11