Call a web service that returns a struct

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

I am trying to access a web service method (that was written in C#) which
returns a structure. I am programming my side in VB.Net.

So the c# struct looks like:
public struct mystruc {
public string result;
public int error;
}

This is what I have in my code, or more to the point, what I have
figured out that works:
Dim xSvc As some.server.WebService
Dim gString As String = xSvc.mystruct().result

So, the question is how do I return the structure into an object (using only
one call) which will allow me to access each of the structures values.
Something like this for example:

Dim xSvc As some.server.WebService
Dim gOB As Object = xSvc.mystruct()

gString = gOB.Result
dError = gOB.Error


I can't seem to find any info on this?
 
Andrew said:
I am trying to access a web service method (that was written in C#) which
returns a structure. I am programming my side in VB.Net.

So the c# struct looks like:
public struct mystruc {
public string result;
public int error;
}

This is what I have in my code, or more to the point, what I have
figured out that works:
Dim xSvc As some.server.WebService
Dim gString As String = xSvc.mystruct().result

So, the question is how do I return the structure into an object (using
only
one call) which will allow me to access each of the structures values.
Something like this for example:

Dim xSvc As some.server.WebService
Dim gOB As Object = xSvc.mystruct()

gString = gOB.Result
dError = gOB.Error


I can't seem to find any info on this?

It would need to be a known XML serialized object returned from the XML Web
service in order for you to cast the object back to a known object type.

You can't use Object because that is a generic object, and even a generic
Object would have to be cast to a known type object for you to address any
properties or methods of the known object type.

The only way you can use it without it being a known object on the client
side would also include that the Web service send it back as a known object
on the Web service side, where as, you can use a "var" on the client side.

I'll assume that "var" can be used in VB like it can be used in C#.

var myobject = xSvc.someWebserviceMethod -- the Web service method returned
a known serialized object on its side to the client.

Then you can do gString = myobject.Result and gError = myobject.Error, if
those are the two properties being sent back for the object sent by the XML
Web service.

If an object is not being sent back by the Web service, then it's going to
the XML that is sent back where it would be a known xsd for the XML that
you would use to address on the client side for Result and Error tags.

That's how things work, and you can't make it up on the client side. The
client side has to know what is coming back from the Web service side, and
then you can do with it what ever you want to after you get it and address
it.
 
Mr. Arnold said:
It would need to be a known XML serialized object returned from the XML Web
service in order for you to cast the object back to a known object type.

You can't use Object because that is a generic object, and even a generic
Object would have to be cast to a known type object for you to address any
properties or methods of the known object type.

The only way you can use it without it being a known object on the client
side would also include that the Web service send it back as a known object
on the Web service side, where as, you can use a "var" on the client side.

I'll assume that "var" can be used in VB like it can be used in C#.

var myobject = xSvc.someWebserviceMethod -- the Web service method returned
a known serialized object on its side to the client.

Then you can do gString = myobject.Result and gError = myobject.Error, if
those are the two properties being sent back for the object sent by the XML
Web service.

If an object is not being sent back by the Web service, then it's going to
the XML that is sent back where it would be a known xsd for the XML that
you would use to address on the client side for Result and Error tags.

That's how things work, and you can't make it up on the client side. The
client side has to know what is coming back from the Web service side, and
then you can do with it what ever you want to after you get it and address
it.

Ok, I understand, so how can I found out what kind of object is being
returned via the WSDL?
 
Mr. Arnold said:
It would need to be a known XML serialized object returned from the XML Web
service in order for you to cast the object back to a known object type.

You can't use Object because that is a generic object, and even a generic
Object would have to be cast to a known type object for you to address any
properties or methods of the known object type.

The only way you can use it without it being a known object on the client
side would also include that the Web service send it back as a known object
on the Web service side, where as, you can use a "var" on the client side.

I'll assume that "var" can be used in VB like it can be used in C#.

var myobject = xSvc.someWebserviceMethod -- the Web service method returned
a known serialized object on its side to the client.

Then you can do gString = myobject.Result and gError = myobject.Error, if
those are the two properties being sent back for the object sent by the XML
Web service.

If an object is not being sent back by the Web service, then it's going to
the XML that is sent back where it would be a known xsd for the XML that
you would use to address on the client side for Result and Error tags.

That's how things work, and you can't make it up on the client side. The
client side has to know what is coming back from the Web service side, and
then you can do with it what ever you want to after you get it and address
it.


Sorry for the second post, but here's something that might help you
understand.

Given the structure that is returned as above. If I declare my variable as
something invalid, the Tool Tip Shows 'Value of Type WebService.mystruct
cannot be converted to ...'
 
Andrew said:
I am trying to access a web service method (that was written in C#) which
returns a structure. I am programming my side in VB.Net.

So the c# struct looks like:
public struct mystruc {
public string result;
public int error;
}

This is what I have in my code, or more to the point, what I have
figured out that works:
Dim xSvc As some.server.WebService
Dim gString As String = xSvc.mystruct().result

So, the question is how do I return the structure into an object (using
only
one call) which will allow me to access each of the structures values.
Something like this for example:

Dim xSvc As some.server.WebService
Dim gOB As Object = xSvc.mystruct()

gString = gOB.Result
dError = gOB.Error


I can't seem to find any info on this?


Is xSvc.mystruct() a function returning a WebService.mystruct object?

I believe that your code above would be:

dim xSvc as some.server.WebService
dim gOB as some.server.WebService.mystruct

gString = gOB.Result
dError = gOB.Error
 
Family Tree Mike said:
Is xSvc.mystruct() a function returning a WebService.mystruct object?

I believe that your code above would be:

dim xSvc as some.server.WebService
dim gOB as some.server.WebService.mystruct

gString = gOB.Result
dError = gOB.Error


Cool! Actually it was:

dim xSvc as some.server.WebService
dim gOB as some.server.mystruct

Thanks Mike! Most appreciated.
 
Mr. Arnold,

The C# "Var" is simple the same as the VB "Dim" as used with option Infer On
in VB. They both are then strongly typed

The Visual Basic Var is a variable, behaves like a kind of non strongly
typed object but then on the stack (Does not exist in to be build VB
versions later then version 6).

Cor
 
The Visual Basic Var is a variable, behaves like a kind of non strongly
typed object but then on the stack (Does not exist in to be build VB
versions later then version 6).

i guess you mean the vb legacy variant datatype with that ?
 
I thought it does not exist anymore after version 6 but that the variant
exist in VBS and VBA, so it is not legacy

Cor
 
Back
Top