Solved

Using non empty parameter Class constructor in Webservice

Posted on 2010-11-14
20
648 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 …
For some reason Google Apps has decided to reserve 'www' for your new domain which results in an error when trying to map the web address 'www' to a certain site in your Google Sites. The error is 'this address is already being used' and after some …
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

18 Experts available now in Live!

Get 1:1 Help Now