By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

problem apparently with type conversion

P: n/a
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..)

Nov 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a

<an*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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..)


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
Nov 23 '05 #2

P: n/a

<an*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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..)


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
Nov 23 '05 #3

P: n/a
Sami Vaaraniemi wrote:
<an*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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..)


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


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

Nov 23 '05 #4

P: n/a
Sami Vaaraniemi wrote:
<an*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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..)


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


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

Nov 23 '05 #5

P: n/a


an*****@gmail.com wrote:
Sami Vaaraniemi wrote:
<an*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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..)


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


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


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.SoapDocumentMethodA ttribute("http://server:13100/imsService/imsServices/getsomestuff",
RequestNamespace:="http://server:13100/imsService/imsServices",
ResponseNamespace:="http://server:13100/imsService/imsServices",
Use:=System.Web.Services.Description.SoapBindingUs e.Literal,
ParameterStyle:=System.Web.Services.Protocols.Soap ParameterStyle.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

Nov 23 '05 #6

P: n/a


an*****@gmail.com wrote:
Sami Vaaraniemi wrote:
<an*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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..)


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


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


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.SoapDocumentMethodA ttribute("http://server:13100/imsService/imsServices/getsomestuff",
RequestNamespace:="http://server:13100/imsService/imsServices",
ResponseNamespace:="http://server:13100/imsService/imsServices",
Use:=System.Web.Services.Description.SoapBindingUs e.Literal,
ParameterStyle:=System.Web.Services.Protocols.Soap ParameterStyle.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

Nov 23 '05 #7

P: n/a
Comments inline:

<an*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...


an*****@gmail.com wrote:
Sami Vaaraniemi wrote:
> <an*****@gmail.com> wrote in message
> news:11**********************@g44g2000cwa.googlegr oups.com...

[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
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..


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

Regards,
Sami
Nov 23 '05 #8

P: n/a
Comments inline:

<an*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...


an*****@gmail.com wrote:
Sami Vaaraniemi wrote:
> <an*****@gmail.com> wrote in message
> news:11**********************@g44g2000cwa.googlegr oups.com...

[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
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..


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

Regards,
Sami
Nov 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.