Using web service

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I need to be able to call a web service method, receive the dataset that web
method returns and store it in an access table. My problem is that I don't
know how to "receive" a complex type like a dataset and how to link it to
the access table that it is supposed to go in. Could someone please give me
a code example?

Thanks

Regards
 
Hi John,

A complete sample it gets an image from disk puts that in an dataset, gives
it to a webserver where it is saved as a dataset, readed again and it uses
as transport a dataset using webservice.
(With the buttons on the form)

It is not ready yet there are no comment lines for that you have to wait
something longer,

However I hope this helps?

Cor

\\\needs a picturebox and 4 buttons on a windowform
Dim ds As New DataSet
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Reading a picture from disk and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray to disk
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a webservice dataset
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(abyt)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a webservice dataset
Dim ws As New localhost.DataBaseUpdate
abyt = ws.GetByte
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
End Class
////
\\\\Webservice
<WebMethod()> _
Public Function GetByte() As Byte()
Dim ds As New DataSet
ds.ReadXml("C:\wsblob.xml")
Return CType(ds.Tables(0).Rows(0)(0), Byte())
End Function
<WebMethod()> _
Public Sub SetDataset(ByVal abyte As Byte())
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType = GetType(System.Byte())
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyte
ds.WriteXml("C:\wsblob.xml", XmlWriteMode.WriteSchema)
End Sub
////
 
Hi,



HYPERLINK
"http://www.onteorasoftware.com/downloads/DibertWebServiceExample.zip"http://www.onteorasoftware.com/downloads/DibertWebServiceExample.zip



Ken

------------------------------------

From: John [mailto:[email protected]]
Sent: Tuesday, June 22, 2004 1:48 PM
To: microsoft.public.dotnet.languages.vb
Subject: Using web service



Hi

I need to be able to call a web service method, receive the dataset that
web
method returns and store it in an access table. My problem is that I
don't
know how to "receive" a complex type like a dataset and how to link it
to
the access table that it is supposed to go in. Could someone please give
me
a code example?

Thanks

Regards
 
Thanks for this. I start reading a remote dataset in bytes wouldn't it be
too slow? Isn't there a way to read at least a record at a time? Otherwise,
can I receive and save the whole dataset locally as xml file, on which I can
open a local dataset?

Thanks

Regards
 
Hi John,

I am curious why you ignore my complete working sample of an XML dataset
with a webservice which does almost exactly as you describe (except the
simple action to place it in an access database)?

Cor
 
Hi Cor

Thanks for that.

Where does ds.WriteXml("C:\wsblob.xml", XmlWriteMode.WriteSchema) store the
xml file? On the pc calling the web service or the server where web service
residues?

My application is slightly different in that I want the remote dataset to
end up in a local access table. For an image image.fromstream makes it easy
but is there an easy way to get the remote dataset into an access table too?

Thanks

Regards
 
Hi John,

You can just move it into the dataset of the acces file, or when the dataset
is equal to the access table you can even insert it. I do not believe in
that because when you than does that twice you have a constraint error. I
think it is better just to get the item from the dataset and set that in the
with the key readed access datatable and than update that.

Than you can update when it exist and insert it when it is new using the
normal dataadapter technique.

However where comes your data from, than I can maybe make a sample what
looks something more like that.

However I am writing this while you no that there is EK, so I review this
tomorrow when this is a problem. Message that than.

In my opinion it is even easier to put it in an Access file than writting it
to disk.

A pity you did not answer earlier, I am busy tomorrow when I have time I
will try to give you an example of that tomorrow but that will than not
early

(When you do not need that message that than)

Cor
 
Hi John,

As told above simple (I have made the access database in this sample, that
is the major part, while I as well have used the dataset which comes direct
from the Access database to keep the sample simple)

I hope this helps?

Cor

\\\
'Needs a form with 2 buttons
'set a reference to ado ext 2.7 for blabla
Private conn As New
OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\db1.mdb;User Id=admin;Password=;")
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim da As New OleDb.OleDbDataAdapter("Select * from countries",
conn)
Dim ds As New DataSet
da.Fill(ds)
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow())
ds.Tables(0).Rows(0)(1) = 1
ds.Tables(0).Rows(0)(2) = "Holland"
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(ds)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
Dim da As New OleDb.OleDbDataAdapter("Select * from countries",
conn)
Dim ds As New DataSet
Dim cmd As New OleDb.OleDbCommandBuilder(da)
Dim ws As New localhost.DataBaseUpdate
ds = ws.GetDataset()
da.Update(ds)
End Sub
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim catNewDB As New ADOX.Catalog
Dim fi As New IO.FileInfo("c:\db1.mdb")
If fi.Exists Then
If MessageBox.Show("Delete?", "Existing File db1.mdb", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data
Source=C:\db1.mdb")
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE countries ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
End Sub
///
\\\
<WebMethod()> _
Public Function GetDataset() As DataSet
Dim ds As New DataSet
ds.ReadXml("C:\wsTest.xml")
Return ds
End Function
<WebMethod()> _
Public Sub SetDataset(ByVal ds As DataSet)
ds.WriteXml("C:\wsTest.xml", XmlWriteMode.WriteSchema)
End Sub
///

,
 
Hi Cor

That's excellent! Thanks for this. Works fine for me.

Regards



Cor Ligthert said:
Hi John,

As told above simple (I have made the access database in this sample, that
is the major part, while I as well have used the dataset which comes direct
from the Access database to keep the sample simple)

I hope this helps?

Cor

\\\
'Needs a form with 2 buttons
'set a reference to ado ext 2.7 for blabla
Private conn As New
OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\db1.mdb;User Id=admin;Password=;")
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim da As New OleDb.OleDbDataAdapter("Select * from countries",
conn)
Dim ds As New DataSet
da.Fill(ds)
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow())
ds.Tables(0).Rows(0)(1) = 1
ds.Tables(0).Rows(0)(2) = "Holland"
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(ds)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
Dim da As New OleDb.OleDbDataAdapter("Select * from countries",
conn)
Dim ds As New DataSet
Dim cmd As New OleDb.OleDbCommandBuilder(da)
Dim ws As New localhost.DataBaseUpdate
ds = ws.GetDataset()
da.Update(ds)
End Sub
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim catNewDB As New ADOX.Catalog
Dim fi As New IO.FileInfo("c:\db1.mdb")
If fi.Exists Then
If MessageBox.Show("Delete?", "Existing File db1.mdb", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data
Source=C:\db1.mdb")
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE countries ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
End Sub
///
\\\
<WebMethod()> _
Public Function GetDataset() As DataSet
Dim ds As New DataSet
ds.ReadXml("C:\wsTest.xml")
Return ds
End Function
<WebMethod()> _
Public Sub SetDataset(ByVal ds As DataSet)
ds.WriteXml("C:\wsTest.xml", XmlWriteMode.WriteSchema)
End Sub
///

,
You can just move it into the dataset of the acces file, or when the dataset
is equal to the access table you can even insert it. I do not believe in
that because when you than does that twice you have a constraint error. I
think it is better just to get the item from the dataset and set that in the
with the key readed access datatable and than update that.

Than you can update when it exist and insert it when it is new using the
normal dataadapter technique.

However where comes your data from, than I can maybe make a sample what
looks something more like that.

However I am writing this while you no that there is EK, so I review this
tomorrow when this is a problem. Message that than.

In my opinion it is even easier to put it in an Access file than
writting
it
to disk.

A pity you did not answer earlier, I am busy tomorrow when I have time I
will try to give you an example of that tomorrow but that will than not
early

(When you do not need that message that than)

Cor
store
the table
too? it
uses
 
Back
Top