Solved

Using non empty parameter Class constructor in Webservice

Posted on 2010-11-14
20
653 Views
Last Modified: 2012-08-13
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(AttributeTargets.All)> _
in other words: I cannot use:
    <AttributeUsage(AttributeTargets.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?
0
Comment
Question by:tuchfeld
  • 9
  • 9
20 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34131165
You should be able to do this

ti(0) = New My_WS. UserInfo(1, "chaim", "baony")
0
 

Author Comment

by:tuchfeld
ID: 34131189
for some reason I can't.
I get an error:
Too many arguments to 'Public Sub New()'.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34131395
That is very strange. Is it public?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:tuchfeld
ID: 34131424
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.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34131869
0
 

Author Comment

by:tuchfeld
ID: 34133899
I looked at the links.
Can You explain.. Can it be done anyway in the way I wanted?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34134467
The workaround is explained in the link above.
0
 

Author Comment

by:tuchfeld
ID: 34141767
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?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 34143222
>Class passed in a WS can have only an Empty constructor?
That appears to be the case.
0
 

Author Closing Comment

by:tuchfeld
ID: 34153064
not much expert in kind of basic knowledge about this issue.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34153475
Did you want me to design a compiler for you which would allow parameterised constructors?
0
 

Author Comment

by:tuchfeld
ID: 34153533
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.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34153575
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."
0
 

Author Comment

by:tuchfeld
ID: 34153637
OK. Thanks. if You want me, I'll update the grade.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34153652
That would be helpful.
0
 

Author Comment

by:tuchfeld
ID: 34153694
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.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34153756
Use the Request Attention button to ask a moderator to change the grade.
0
 

Author Comment

by:tuchfeld
ID: 34153773
OK.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get number of Files in Directory and Sub Directories 2 48
VB.net and sql server 4 45
VB.NET 2008 - Windows Protected Your PC 7 42
VB.NET Inline If statement 4 18
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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