Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 22nd, 2009, 04:11 PM
Authorized User
 
Join Date: Jun 2009
Posts: 70
Thanks: 18
Thanked 1 Time in 1 Post
Default Development form page 388 - using web service

Hope it's OK to ask this here. I want to develop a web page similar to page Genres.aspx - but using a web service to get an xml file from another server, instead of SQL tables from a local one. For testing, I have the web service on line at another web site (call it website2) - in practice it will be on a server at work.

Rather than coming from SQL tables, the data will come from an xml file on website2. I have found that I can create a the web service - and access it and hence the xml file via a dataset - but my coding is getting messy - moreover, so far I have been able only to read and edit the data - but not update the file itself. I had thought what I am trying to do would be a fairly simple extension of what I had done in the book - but that's not been so. Nevertheless, I have gone back to the book example to try and re-start.

Two questions:

1. Up until now, I have bound the grid view to the dataset in the code-behind - but have not seen away to show that as the data source in the GridView smart tag - may be because the datasource does not lead to full Gridview functionality. Could you suggest a better way of declaring the data set - and also comment on how the dataset and web method could allow writing as well as reading?

Web method
Code:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://example.com/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class transxml
    Inherits System.Web.Services.WebService

    <WebMethod()> Public Function GetXmlFile() As XmlNode
        Dim doc As New XmlDocument()
        doc.Load(Server.MapPath("Tester/test.xml"))
        Return doc.DocumentElement
    End Function
End Class
Datasorce declaration

Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ws As New BooksInfo.transxml()
        Dim element As XmlElement = DirectCast(ws.GetXmlFile(), XmlElement)
        Dim ds As New DataSet()
        Dim xnr As New XmlNodeReader(element)
        ds.ReadXml(xnr)

        GridView1.DataSource = ds
        GridView1.DataBind()

    End Sub
[code]

Question 2.

When I do get the dataset sorted out - looking at the Genres.aspx example for reference - would it be sensible to replace
Code:
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" DeleteCommand="DELETE FROM [Genre] WHERE [Id] = @Id" InsertCommand="INSERT INTO [Genre] ([Name], [SortOrder]) VALUES (@Name, @SortOrder)" ProviderName="<%$ ConnectionStrings:PlanetWroxConnectionString1.ProviderName %>" SelectCommand="SELECT [Id], [Name], [SortOrder] FROM [Genre]" UpdateCommand="UPDATE [Genre] SET [Name] = @Name, [SortOrder] = @SortOrder WHERE [Id] = @Id">
with an XMLDataSource expression?
 
Old September 23rd, 2009, 07:35 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
on how the dataset and web method could allow writing as well as reading?
For this to work, you need to create a web service method that allows updates.

The SqlDataSource (and many other DataSource controls) are designed to be read/write. In your case, you need to recreate this behavior if you want to do this through web services. Selecting data from an XML file is easy as you found out, but you need more work to update the file again. You may find this useful: http://aspnet.4guysfromrolla.com/articles/112603-1.aspx

It's a bit dated article, but it shows the general principle.

To learn more about editing XML with the XmlDataSource, take a look here: http://msdn.microsoft.com/en-us/libr...atasource.aspx

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
kiwibrit (September 23rd, 2009)
 
Old September 23rd, 2009, 09:58 AM
Authorized User
 
Join Date: Jun 2009
Posts: 70
Thanks: 18
Thanked 1 Time in 1 Post
Default

Thanks Imar - very helpful.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Code page 388 NadAf BOOK: Ivor Horton's Beginning Visual C++ 2005 0 February 18th, 2008 11:24 PM
ERRATA on page 388 NadAf BOOK: Ivor Horton's Beginning Visual C++ 2005 0 August 15th, 2007 09:40 PM
Web Form and Service jhawar .NET Web Services 2 August 8th, 2004 07:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.