Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / July 2005

Tip: Looking for answers? Try searching our database.

problem apparently with type conversion

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
andyjgw@gmail.com - 07 Jul 2005 12:05 GMT
Hi all, hope someone can help here, I'm really stuck. Reading and
googling like mad, to no avail so far...

Basically, my problem *seems* to boil down to type conversion:

Here's a sample web service I knocked up:

   <WebMethod()> _
   Public Function HelloWorld() As myType
       Return New myType("Andrew", "too old")
   End Function

End Class

Public Class myType
   Private _name, _age As String
   Property name() As String
       Get
           Return _name
       End Get
       Set(ByVal Value As String)
           _name = Value
       End Set
   End Property

   Property age() As String
       Get
           Return _age
       End Get
       Set(ByVal Value As String)
           _age = Value
       End Set
   End Property
   Sub New()
   End Sub
   Sub New(ByVal n As String, ByVal a As String)
       _name = n
       _age = a
   End Sub
End Class

In my main application, I have a copy of the myType class, it's
identical, but when I do this:

       Dim myLocalType As myType
       Dim svc As mytest.Service1
       myLocalType = svc.HelloWorld  <<< error

it throws an error of "value of type 'imsws.mytest.mytype' cannot be
converted to 'imsws.mytype'". They are exactly the same type! The web
reference reference.vb shows:

<System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://tempuri.org/imsService/Service1")>
_
   Public Class myType

       '<remarks/>
       Public name As String

       '<remarks/>
       Public age As String
   End Class

I'm really stuck here - can you help? Thanks in advance if so :)

Cheers

AW (beginning to sweat a little..)
Sami Vaaraniemi - 08 Jul 2005 09:20 GMT
> Hi all, hope someone can help here, I'm really stuck. Reading and
> googling like mad, to no avail so far...
[quoted text clipped - 64 lines]
>
> AW (beginning to sweat a little..)

A copy of your type is created along with the Web Service proxy. This
generated copy is similar to but is *not* the same as the original type,
hence the compiler error. You are supposed to use the type that comes with
the proxy.

That said, you can edit the generated proxy code and remove the generated
type and have it reference the original type. This would work almost as if
the Web Service returned your original type, except that any private state
is lost. Also note that any changes to the proxy code are lost as soon as
you regenerate the proxy.

It's a lot less hassle to just use the types generated with the proxy. This
is the way it is intended anyway.

Regards,
Sami
andyjgw@gmail.com - 09 Jul 2005 11:10 GMT
> > Hi all, hope someone can help here, I'm really stuck. Reading and
> > googling like mad, to no avail so far...
[quoted text clipped - 81 lines]
> Regards,
> Sami

Hi Sami

Thanks for that. One snag with using the referenced types appears to be
that my methods for the class don't all appear in the way I need them.
Basically, I can of course expose them as webmethods, but I have lots
of simple methods that just perform simple calculations that I would
much rather handle 'locally' that via a web request each time.

Could you suggest how I might resolve this?

Thanks for your help.

AW
andyjgw@gmail.com - 11 Jul 2005 15:58 GMT
> > > Hi all, hope someone can help here, I'm really stuck. Reading and
> > > googling like mad, to no avail so far...
[quoted text clipped - 95 lines]
>
> AW

Forget that - I've solved that part of the  problem by referencing a
common type defined in a common namespace. Found the dox on how to do
this at MSDN (eventually).

However, I seem to have a problem returning a value from my webservice
now: I created a 'local' copy of the webservice and it ran fine. When I
run it remote, it returns an empty list.

Any thoughts?

Here's a snippet:

       <WebMethod()> Function getsomestuff() As Envelope
           Return New Envelope(1, 2, 3, 4)
       End Function

And in my generated Reference.vb:

<System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://server:13100/imsService/imsServices/getsomestuff",
RequestNamespace:="http://server:13100/imsService/imsServices",
ResponseNamespace:="http://server:13100/imsService/imsServices",
Use:=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)>
_
       Public Function getsomestuff() As Envelope
           'Return New Envelope(1100, 2200, 3300, 4400)
           Dim results() As Object = Me.Invoke("getsomestuff", New
Object(-1) {})
           Return CType(results(0), Envelope)
       End Function

       '<remarks/>
       Public Function Begingetsomestuff(ByVal callback As
System.AsyncCallback, ByVal asyncState As Object) As
System.IAsyncResult
           Return Me.BeginInvoke("getsomestuff", New Object(-1) {},
callback, asyncState)
       End Function

       '<remarks/>
       Public Function Endgetsomestuff(ByVal asyncResult As
System.IAsyncResult) As Envelope
           Dim results() As Object = Me.EndInvoke(asyncResult)
           Return CType(results(0), Envelope)
       End Function

When that returns, I don't get my 1,2,3,4 as expected - I get 0,0,0,0
which is the default for a new envelope. If I uncomment the hard-coded
return above (1100, 2200 etc) then that works fine and I get those
numbers back as expected.

Any ideas why?

Thanks in advance - the finish line is in sight, but it's a struggle
all the way at the moment..

Thanks
AW
Sami Vaaraniemi - 12 Jul 2005 08:33 GMT
Comments inline:

[snip]

> Forget that - I've solved that part of the  problem by referencing a
> common type defined in a common namespace. Found the dox on how to do
> this at MSDN (eventually).

Yes, this is what you can do, with a couple of caveats (see below).

> However, I seem to have a problem returning a value from my webservice
> now: I created a 'local' copy of the webservice and it ran fine. When I
> run it remote, it returns an empty list.
>
> Any thoughts?

Could it be that the data that is missing is private? Make sure that the
fields (properties or methods) are public in the class. Otherwise they won't
be included in XML serialization. This is what I meant earlier by saying
that 'private state is lost'.

> When that returns, I don't get my 1,2,3,4 as expected - I get 0,0,0,0
> which is the default for a new envelope. If I uncomment the hard-coded
[quoted text clipped - 5 lines]
> Thanks in advance - the finish line is in sight, but it's a struggle
> all the way at the moment..

It is admittably a bit of a hassle if you want to share types this way.

Regards,
Sami

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.