Exposing Structures from WebService

  • Thread starter Thread starter Nikolay Petrov
  • Start date Start date
N

Nikolay Petrov

In my WebService I have structure

Structure myStr1
Dim text as String
Dim Key as Byte()
End Structure

and a Web Method, containing Function which retruns data as this Structure

My qustion is, How to expose this structure to my apps, so they can use it?

TIA
 
Nikolay,

I would never do it this way, however the shortest sample I could make from
it to give you an idea.
\\\
<WebMethod()> _
Public Function GiveFields() As MyFields
Dim myrecord As New MyFields
myrecord.fielda = "Hello"
myrecord.fieldb = "World"
Return myrecord
End Function
Structure MyFields
Public fielda As String
Public fieldb As String
End Structure
///
\\\add this to the webproject and set a reference to the project itself
\\\a listbox on this form
Private Sub Form1_Load(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles MyBase.Load
Dim myservice As New localhost.NewService
Dim a As localhost.MyFields = myservice.GiveFields
ListBox1.Items.Add(a.fielda)
ListBox1.Items.Add(a.fieldb)
End Sub
///

I hope this helps you a little bit?

Cor


"Nikolay Petrov"
..
 
What way you would use, then?


Cor Ligthert said:
Nikolay,

I would never do it this way, however the shortest sample I could make
from it to give you an idea.
\\\
<WebMethod()> _
Public Function GiveFields() As MyFields
Dim myrecord As New MyFields
myrecord.fielda = "Hello"
myrecord.fieldb = "World"
Return myrecord
End Function
Structure MyFields
Public fielda As String
Public fieldb As String
End Structure
///
\\\add this to the webproject and set a reference to the project itself
\\\a listbox on this form
Private Sub Form1_Load(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles MyBase.Load
Dim myservice As New localhost.NewService
Dim a As localhost.MyFields = myservice.GiveFields
ListBox1.Items.Add(a.fielda)
ListBox1.Items.Add(a.fieldb)
End Sub
///

I hope this helps you a little bit?

Cor


"Nikolay Petrov"
.
 
Cor,
I don't see the localhost.MyFields in my client app. I see the
myservice.GiveFields function, but not the structure. I've made it public,
but without improvement.
 
Nikolay,

Did you set a normal reference in you program to that project?

In the solution explorer
references ->right click ->add reference ->projects -> etc

And you have everytime to build and update the webservice when you make
changes in that.

Cor
 
Yes, i've added Web reference. And I am updating it every time I make change
 
Nikolay,

Not a webreference, you have to tell where the description of your structure
is with a normal reference. Did you try it as I said?

Cor
 
Yes, use a Web Reference. Once the web reference is added, look at the files
it creates. One of them should be Reference.vb, in there will be the
structure definition. On my maching it looks like:

<System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://tempuri.org/
TestWebService/Service1")> _
Public Class myStr1
'<remarks/>
Public [text] As String
'<remarks/>

<System.Xml.Serialization.XmlElementAttribute(DataType:="base64Binary")> _
Public Key() As Byte
End Class

You should not use a regular reference.

JD
 
JD,

You are right.

It should work direct after rebuilding the application and updating the
webservice.

Cor

JD said:
Yes, use a Web Reference. Once the web reference is added, look at the
files
it creates. One of them should be Reference.vb, in there will be the
structure definition. On my maching it looks like:

<System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://tempuri.org/
TestWebService/Service1")> _
Public Class myStr1
'<remarks/>
Public [text] As String
'<remarks/>

<System.Xml.Serialization.XmlElementAttribute(DataType:="base64Binary")> _
Public Key() As Byte
End Class

You should not use a regular reference.

JD

Nikolay Petrov said:
Yes, i've added Web reference. And I am updating it every time I make change
 
No, I didn't. So I have to browse to my webservice project and add it as
normal reference?
I'll do it right now.

But this raises new question.
When I publish my web service, how other peaple will add this reference?
 
Nikolay,

That is why I told that I would not do it in your way however take a more
common datasource.

Cor
 
I am missing something, JD
What sould I do with the definition in Reference.vb?



JD said:
Yes, use a Web Reference. Once the web reference is added, look at the
files
it creates. One of them should be Reference.vb, in there will be the
structure definition. On my maching it looks like:

<System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://tempuri.org/
TestWebService/Service1")> _
Public Class myStr1
'<remarks/>
Public [text] As String
'<remarks/>

<System.Xml.Serialization.XmlElementAttribute(DataType:="base64Binary")> _
Public Key() As Byte
End Class

You should not use a regular reference.

JD

Nikolay Petrov said:
Yes, i've added Web reference. And I am updating it every time I make change
 
Use it to call the webservice.

Nikolay Petrov said:
I am missing something, JD
What sould I do with the definition in Reference.vb?



JD said:
Yes, use a Web Reference. Once the web reference is added, look at the
files
it creates. One of them should be Reference.vb, in there will be the
structure definition. On my maching it looks like:

<System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://tempuri.org/
TestWebService/Service1")> _
Public Class myStr1
'<remarks/>
Public [text] As String
'<remarks/>

<System.Xml.Serialization.XmlElementAttribute(DataType:="base64Binary")> _
Public Key() As Byte
End Class

You should not use a regular reference.

JD

Nikolay Petrov said:
Yes, i've added Web reference. And I am updating it every time I make change


Nikolay,

Did you set a normal reference in you program to that project?

In the solution explorer
references ->right click ->add reference ->projects -> etc

And you have everytime to build and update the webservice when you make
changes in that.

Cor


"Nikolay Petrov" <[email protected]>

Cor,
I don't see the localhost.MyFields in my client app. I see the
myservice.GiveFields function, but not the structure. I've made it
public, but without improvement.

Nikolay,

I would never do it this way, however the shortest sample I could
make
from it to give you an idea.
\\\
<WebMethod()> _
Public Function GiveFields() As MyFields
Dim myrecord As New MyFields
myrecord.fielda = "Hello"
myrecord.fieldb = "World"
Return myrecord
End Function
Structure MyFields
Public fielda As String
Public fieldb As String
End Structure
///
\\\add this to the webproject and set a reference to the project itself
\\\a listbox on this form
Private Sub Form1_Load(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles MyBase.Load
Dim myservice As New localhost.NewService
Dim a As localhost.MyFields = myservice.GiveFields
ListBox1.Items.Add(a.fielda)
ListBox1.Items.Add(a.fieldb)
End Sub
///

I hope this helps you a little bit?

Cor


"Nikolay Petrov"
.
In my WebService I have structure

Structure myStr1
Dim text as String
Dim Key as Byte()
End Structure

and a Web Method, containing Function which retruns data as this
Structure

My qustion is, How to expose this structure to my apps, so they
can
use
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top