Solved

Using non empty parameter Class constructor in Webservice

Posted on 2010-11-14
20
654 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

2017 Webroot Threat Report

MSPs: Get the facts you need to protect your clients.
The 2017 Webroot Threat Report provides a uniquely insightful global view into the analysis and discoveries made by the Webroot® Threat Intelligence Platform to provide insights on key trends and risks as seen by our users.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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