Asp. NET Instance Tutorial: subscribing to GeoRSS feeds

Source: Internet
Author: User
Tags add format implement net string tostring port number visual studio

In this exercise, you will implement the HTTP handler in the ASP.net Web application to return the GeoRSS feed. GeoRSS is a standard used to include geospatial data in RSS feeds that defines a specific format called GeoRSS GML that contains GML-formatted data in the feed. Client applications can subscribe to GeoRSS feeds in the same way that they subscribe to regular RSS feeds. You can easily import GeoRSS-formatted data into the Microsoft Virtual Earth VEMap control.

Note: You can copy the code used in this exercise from the completed Web site page in C:\SQLHOLS\Spatial and Ve\solution\storefindersite.

Implementing an HTTP Handler

1. Start Microsoft Visual Studio 2008.

2. In the File menu, click Open the Web site, and then open the C:\SQLHOLs\Spatial and Ve\starter\storefindersite Web site.

3. In Solution Explorer, expand App_Code, and then double-click Georsshandler.vb to open it in the Code Editor.

Note: The HTTP handler is a code module that handles HTTP requests for WEB applications. A request for a asp.net Web application is typically handled by the default ASP.net request handler, but you can create a custom handler for a specific file name extension. In this example, you will implement a handler that will be used to process requests for files with the. georss extension.

4. Check the existing code. The process of processing an incoming request is named ProcessRequest. Note that this process is incomplete and contains a large number of comments that must be added to the code.

5. Under the annotation build the GeoRSS feed, add the following code to begin building the GeoRSS feed that will be returned by the HTTP handler.

 
  
  

The following are the referenced contents:

Rssoutput.appendline ("
Rssoutput.appendline ("xmlns:georss= ' Http://www.georss.org/georss '")
Rssoutput.appendline ("xmlns:gml= ' Http://www.opengis.net/gml ' >")
Rssoutput.appendline ("")
Rssoutput.appendline ("Store locations")
Rssoutput.appendline ("")
Rssoutput.appendline ("" + System.DateTime.Now + "")
Rssoutput.appendline ("")
Rssoutput.appendline ("SQL Server")
Rssoutput.appendline ("")

6. Under the comment Open a connection to the database, add the following code.

 
  
  

The following are the referenced contents:

Sqlconn.open ()

7. Add the following code under the annotation use of the getstoresgml stored proc to get all stores by default.

 
  
  

The following are the referenced contents:

Spname = "GETSTORESGML"

Note: By default, a request to this HTTP handler invokes the GETSTORESGML stored procedure and returns a GeoRSS feed containing all stores.

8. In the note If a searchfrom parameter is provided, use getnearbystores and add the provided lat and lon coordinates as parameter s, add the following code.

 
  
  

The following are the referenced contents:

Dim searchfrom as String = context . Request.QueryString ("Searchfrom")
If not searchfrom are nothing Then
Spname = "GETNEARBYSTORESGML"
Dim Latlong () as String = Split(Searchfrom, ",", 2)
Cmd. Parameters.Add (New SqlParameter ("Lat", Latlong (0))
Cmd. Parameters.Add (New SqlParameter ("Long", Latlong (1))
End If

Note: If the request contains a parameter named Searchfrom (assuming it contains a comma-delimited latitude and longitude coordinate pair), the handler extracts the latitude and longitude values from this parameter and uses the GETNEARBYSTORESGML stored procedure to return the GeoRSS feed. The subscription source contains the requested search point around a range of shops within a radius of km.

9. Add the following code under the annotation specify the stored procedure name as the command text (specifying the stored procedure name as the command-line).

 
  
  

The following are the referenced contents:

Cmd.commandtext = Spname

10. Under annotation Create an element for this row, add the following code to create a tag for each row in the result of the stored procedure.

 
  
  

The following are the referenced contents:

Rssoutput.appendline ("")

11. Under the note Use columns 0 and 1 for the title and description, add the following code to create according to the data returned by the stored procedure ", Geomrdr.getvalue (0)))

 
  
  

The following are the referenced contents:

Rssoutput.appendline (String.Format ("{0}", _
Geomrdr.getvalue (1))

12. Under comment Add a, add the following code to create an element for this entry.
 
  
  

The following are the referenced contents:

Rssoutput.appendline ("")

13. Under the comment get the geography instance GML from column 2, add the following code to retrieve the GML data from the stored procedure results.

 
  
  

The following are the referenced contents:

GML = Geomrdr.getvalue (2). ToString ()

14. Under the annotation add the elements to the output XML, add the following code to add GML data to the GeoRSS feed source.

 
  
  

The following are the referenced contents:

Rssoutput.appendline (GML)

15. Under note Close and elements, add the following code.

 
  
  

The following are the referenced contents:

Rssoutput.appendline ("")
Rssoutput.appendline ("")

16. Under the note close the document and send it as the response, add the following code to complete the GeoRSS feed and send it to the requestor.

 
  
  

The following are the referenced contents:

Rssoutput.append ("")
Context. Response.Write (Rssoutput.tostring ())

17. Save Georsshandler.vb.

Registering an HTTP handler

1. In Solution Explorer, double-click Web.config to open it in the editor.

2. In the section, under the comment Register the georsshandler for. GeoRSS requests, add the following XML.

 
  
  

The following are the referenced contents:

<add verb= "*" path= "*.georss" type= "Georsshandler" validate= "false"/>

Note: You must register HTTP handlers for specific file extensions so that Internet information Services forwards requests for those files to the correct handlers.

3. Save Web.config.

Testing HTTP Handlers

1. In Solution Explorer, click the Web site project file that is located under the root of the tree, and then press F4 to view its properties.

2. Watch for the port number properties.

3. On the Site menu, click the startup option.

4. Select the Startup URL, enter the following URL (replace port with the value of the port Number property of the Web site), and then click OK.

Http://localhost:/storefindersite/test.georss

5. On the Debug menu, click Start Execution (without debugging).

6. When the Microsoft Internet explorer® is open, view the page that contains the RSS feed for the store name.

7. In Internet Explorer, right-click anywhere on the Web page, and then click View Source to open the source file for that page in Notepad. Note that the source of the page is the GeoRSS subscription source generated by the HTTP handler that you created earlier.

8. Close Notepad.

9. In the Address bar in Internet Explorer, append the following query string to the URL, and then press Enter.

? searchfrom=34.000000,-118.000000

10. Verify that the generated GeoRSS feed contains the search area and all stores in it.

11. Turn off Internet Explorer.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.