HighTechTalks DotNet Forums  

Can't provide constructor parameters

ASP.net Web Services microsoft.public.dotnet.framework.aspnet.webservices


Discuss Can't provide constructor parameters in the ASP.net Web Services forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
John Granade
 
Posts: n/a

Default Can't provide constructor parameters - 11-30-2007 , 05:34 PM






It seems like this should be easy but I must be missing something...I'm
trying to create a web service class that accepts is instantiated with
parameters but I always get just the new() option (parameterless). Here's a
very simple example of what I've tried.

------Web Service----------
<System.Web.Services.WebService(Namespace:="http ://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo: =WsiProfiles.BasicProfile1_1)>
_
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
Private _text As String

Protected Sub New()
End Sub

Public Sub New(ByVal Text As String)
_text = Text
End Sub

<WebMethod()> _
Public Function GetText() As String
Return _text
End Function
End Class
---------------------------

I added the Protected New sub because I read that you must have one
parameterless constuctor to create a serializable class and it certainly
gives an error if you don't. The above code looks simple enough to me but
when I try to call it in my client it doesn't show a class that can be
created with parameters.

If I add a reference to the web service called 'ws', then in my code when I
try to do somethign like "dim s as New ws.Service1("text")" is says "too
many arguments to 'Public Sub New()' (which I knew because Intellisense
doesn't show any parameters when I typed ws.Service1). But why does it even
see 'Public Sub New()' when I set it to Protected and why doesn't it see
'public sub new (by val text as string)'?

I've been Googling it to death and I can't find anything on this. I see
examples that seem to instantial the web methods with parameters but not
working code. The code above is from a brand new web service project and a
windows client calling it so I don't know how to simplify it any more.

Thanks for any help.

John
John<nospam>@GTSolutions.us


Reply With Quote
  #2  
Old   
John Granade
 
Posts: n/a

Default Re: Can't provide constructor parameters - 12-02-2007 , 10:09 PM






Thanks for the insight. I still feel like I'm missing something simple.
What I really have is a web service that receives an arraylist and I'm
wanting to load that arraylist with my class object. For instance, if my
class just defined two properties (PropertyName and PropertyValue) I was
hoping I could do something like this on the client end...

arraylist.add( new webservice.myClassInfo("text", "value"))
arraylist.add(new webserive.myClassInfo("text2", "value2"))

But since my custom class that's defined from the web service can't take
parameters, I have to do...

dim x as new webservice.myClassInfo
x.PropertyName = "text"
x.PropertyValue = "value"
arraylist.add(x)

dim y as new webservice.myClassInfo
y.PropertyName = "text2"
y.PropertyValue = "value2"
arraylist.add(y)

It still works but it's a lot more lines of code but I'll just do this for
now and refactor later. It's going to bug me though...

Thanks,

John


"Dave Bush" <davembush (AT) dmbcllc (DOT) com> wrote

Quote:
The Web Service isn't REALLY a class. .NET just uses the class mechanism
to make it easy for us to create them. But the web service standard has
no knowledge of what we are doing and is really just letting us call the
individual methods in them. You'll notice there isn't any ability to call
a property either.

What we create as an object on the client side is just a proxy to call the
web service. All the web service or the client knows about really are the
methods in our class that we've marked with the "WebMethod" attribute and
are public.

Dave Bush
http://blog.dmbcllc.com

It seems like this should be easy but I must be missing
something...I'm trying to create a web service class that accepts is
instantiated with parameters but I always get just the new() option
(parameterless). Here's a very simple example of what I've tried.

------Web Service----------
System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
System.Web.Services.WebServiceBinding(ConformsTo:= WsiProfiles.BasicPr
ofile1_1)
_
ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
Private _text As String
Protected Sub New()
End Sub
Public Sub New(ByVal Text As String)
_text = Text
End Sub
WebMethod()> _
Public Function GetText() As String
Return _text
End Function
End Class
---------------------------

I added the Protected New sub because I read that you must have one
parameterless constuctor to create a serializable class and it
certainly gives an error if you don't. The above code looks simple
enough to me but when I try to call it in my client it doesn't show a
class that can be created with parameters.

If I add a reference to the web service called 'ws', then in my code
when I try to do somethign like "dim s as New ws.Service1("text")" is
says "too many arguments to 'Public Sub New()' (which I knew because
Intellisense doesn't show any parameters when I typed ws.Service1).
But why does it even see 'Public Sub New()' when I set it to Protected
and why doesn't it see 'public sub new (by val text as string)'?

I've been Googling it to death and I can't find anything on this. I
see examples that seem to instantial the web methods with parameters
but not working code. The code above is from a brand new web service
project and a windows client calling it so I don't know how to
simplify it any more.

Thanks for any help.

John
John<nospam>@GTSolutions.us




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.