0

Google マップと weather.com のマッシュアップを作成しましたが、これらのサーバーのいずれかが応答しないたびに、アプリケーションもハングアップします。Web アプリケーションのハングアップを防止または最小限に抑えるにはどうすればよいと思いますか?そのページから離れて移動する.... 天気予報サービスにアクセスするために、アプリ コードでこのコードを取得しました。


Public Class WeatherIn
    Private _path As String
    Private _cachedFile As String
     Public Sub New(ByVal path As String)
        _path = path
        _cachedFile = String.Format("{0}\WeatherInCache.xml", _path)
    End Sub

Public Function GetWeather(ByVal arg As String) As String

    Return _getWebWeather(arg)

End Function

Private Function _getCachedWeather() As String
    Dim str As String = String.Empty


    Using reader As New StreamReader(_cachedFile)
        str = reader.ReadToEnd()
    End Using


    Return str
End Function

Private Function _getWebWeather(ByVal arg As String) As String

    Dim baseUrl As String = "http://xoap.weather.com/weather/local/{0}?cc=*&dayf=5&link=xoap&prod=xoap&par={1}&key={2}"
    Dim jane As String = arg
    Dim james As String = "api key"
    Dim john As String = "another api key"

    Dim url As String = String.Format(baseUrl, jane, james, john)


    Using client As New WebClient()

        Try

            Dim xml As New XmlTextReader(client.OpenRead(url))


            Dim xslt As New XslCompiledTransform()
            xslt.Load(_path + "/Pathto.xslt")


            Using writer As New StreamWriter(_cachedFile)
                xslt.Transform(xml, Nothing, writer)
            End Using


            Return _getCachedWeather()
        Catch exception As WebException

            Dim xmlStr As String = "<errorDoc>"
            xmlStr += "<alert>An Error Occurred!</alert>"
            xmlStr += [String].Format("<message>{0}</message>", exception.Message)
            xmlStr += "</errorDoc>"


            Dim doc As New XmlDocument()
            doc.LoadXml(xmlStr)


            Dim reader As New XmlNodeReader(doc)

            Dim xslt As New XslCompiledTransform()
            xslt.Load(_path + "/Pathto.xslt")


            Dim resultDocument As New XmlDocument()
            Using writer As XmlWriter = resultDocument.CreateNavigator().AppendChild()
                xslt.Transform(reader, DirectCast(Nothing, XsltArgumentList), writer)
            End Using

            Return resultDocument.OuterXml
        End Try
    End Using
End Function

次に、私のページで上記のクラスを使用して、次のように天気を表示します。



'specific zip code or could be retrieved from querystring for dynamic retrieval

var jay="94576" 

Dim weather As New WeatherIn(Server.MapPath(String.Empty))
                Dim weatherData As String = weather.GetWeather(jay)


                Response.ContentType = "text/xml"
                Response.CacheControl = "no-cache"

                Response.Write(weatherData)

データを取得し、javascript を使用してページに書き込みます。ほとんどの場合、ダウンするのは weather.com です。信頼できる Google マップに問題はありません。リモート サーバーが応答していませんか?リモート サーバーが応答している場合、マッシュアップはスムーズに実行されています...

4

1 に答える 1