tuchfeld
asked on
Using non empty parameter Class constructor in Webservice
Hi,
I'm using WS successfully,
but I wonder why I cannot have a non empty parameter constructor for a class
declared with the header:
<AttributeUsage(AttributeT argets.All )> _
in other words: I cannot use:
<AttributeUsage(AttributeT argets.All )> _
Public Class UserInfo
Public Sub New(ByVal id As Integer, ByVal first_name As String, ByVal last_name As String)
Me.id = id
Me.first_name = first_name
Me.last_name = last_name
End Sub
Unless I have an empty constructor:
Public Sub New()
End Sub
But then need at the other side to use like this:
Dim ti(2) As My_WS. UserInfo
ti(0) = New My_WS. UserInfo()
ti(0).id = 1
ti(0).first_name = "chaim"
ti(0).last_name = "baony"
Which is inconvenient.
How can I use a non empty parameter constructor for WS Class?
I'm using WS successfully,
but I wonder why I cannot have a non empty parameter constructor for a class
declared with the header:
<AttributeUsage(AttributeT
in other words: I cannot use:
<AttributeUsage(AttributeT
Public Class UserInfo
Public Sub New(ByVal id As Integer, ByVal first_name As String, ByVal last_name As String)
Me.id = id
Me.first_name = first_name
Me.last_name = last_name
End Sub
Unless I have an empty constructor:
Public Sub New()
End Sub
But then need at the other side to use like this:
Dim ti(2) As My_WS. UserInfo
ti(0) = New My_WS. UserInfo()
ti(0).id = 1
ti(0).first_name = "chaim"
ti(0).last_name = "baony"
Which is inconvenient.
How can I use a non empty parameter constructor for WS Class?
ASKER
for some reason I can't.
I get an error:
Too many arguments to 'Public Sub New()'.
I get an error:
Too many arguments to 'Public Sub New()'.
That is very strange. Is it public?
ASKER
Yes.
Notice that if I do not supply:
Public Sub New()
End Sub
it gives error:
cannot be serialized because it does not have a parameterless constructor.
Notice that if I do not supply:
Public Sub New()
End Sub
it gives error:
cannot be serialized because it does not have a parameterless constructor.
ASKER
I looked at the links.
Can You explain.. Can it be done anyway in the way I wanted?
Can You explain.. Can it be done anyway in the way I wanted?
The workaround is explained in the link above.
ASKER
Yes - it says: "... you can try to use another method to initialize all the member fields for workaround."
Obviousely, this is a workaround.
So, Can You state that it cannot be done?
i.e.: Class passed in a WS can have only an Empty constructor?
Obviousely, this is a workaround.
So, Can You state that it cannot be done?
i.e.: Class passed in a WS can have only an Empty constructor?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
not much expert in kind of basic knowledge about this issue.
Did you want me to design a compiler for you which would allow parameterised constructors?
ASKER
Please don't be rude.
1) You wrote: "That appears to be the case"
Not much confident answer..
2) A short explanation for the Reason (why is it not allowed).
Would give A grade.
1) You wrote: "That appears to be the case"
Not much confident answer..
2) A short explanation for the Reason (why is it not allowed).
Would give A grade.
If you had bothered to read the links I pasted, you would have come across this explanation:
"Web services are intended to be loosely coupled. Your web services exposes describes its operations and data types in WSDL and XML Schema documents that a client can use to generate a proxy for calling the web service. The schema for the data types only preserves the structure of the data - it doesn't preserve aspects of your type that are specific to the .NET Framework. For example, a Java client can call your web service just as easily as a .NET client. Constructors are one of the aspects of a .NET type that are not relevant to the structure of the data and are not preserved in schema."
"Web services are intended to be loosely coupled. Your web services exposes describes its operations and data types in WSDL and XML Schema documents that a client can use to generate a proxy for calling the web service. The schema for the data types only preserves the structure of the data - it doesn't preserve aspects of your type that are specific to the .NET Framework. For example, a Java client can call your web service just as easily as a .NET client. Constructors are one of the aspects of a .NET type that are not relevant to the structure of the data and are not preserved in schema."
ASKER
OK. Thanks. if You want me, I'll update the grade.
That would be helpful.
ASKER
BTW. "If I had bothered to read..."
I'd buy WS book..
So I suggest that You should add some addiional info beside the link(s).
Anyway, where should I click to update the grade?
and Thanks.
I'd buy WS book..
So I suggest that You should add some addiional info beside the link(s).
Anyway, where should I click to update the grade?
and Thanks.
Use the Request Attention button to ask a moderator to change the grade.
ASKER
OK.
ti(0) = New My_WS. UserInfo(1, "chaim", "baony")