天气网络服务 [英] Weather Web Service

查看:64
本文介绍了天气网络服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VB2010
在代码屏幕上没有显示任何错误,但是当我调试它进行测试并准备接收时,我的消息框显示网络服务不可用".弹出.
它内置有用于输入邮政编码的文本框,用于天气或天气预报的组合框,用于返回的lblForecast.三个按钮提交,清除和退出.提交是一个按钮,不起作用.

方法是:
GetCityForecastByZIP(ZIP作为字符串)作为ForecastReturn
允许您获取未来7天的城市天气预报,该报告每小时更新一次.仅限美国

GetCityWeatherByZIP(邮政编码为字符串)为WeatherReturn
允许您获取每小时更新一次的城市天气".仅限美国

我需要一个示例或逐步纠正.我是VB的新手,碰到这堵墙,觉得我很亲近.预先感谢您的帮助,我在这里确实很挣扎.

VB2010
there are no errors showing on the code screen but when I debug it to test it and goes to receive, my message box saying "web service not available" pops up.
It is built with a Text Box for Zip entry, Combo box for Weather or forecast, lblForecast for return. Three buttons Submit, Clear, and Exit. Submit is the one button not working.

The methods are:
GetCityForecastByZIP ( ZIP As string ) As ForecastReturn
Allows you to get your City Forecast Over the Next 7 Days, which is updated hourly. U.S. Only

GetCityWeatherByZIP ( ZIP As string ) As WeatherReturn
Allows you to get your City's Weather, which is updated hourly. U.S. Only

I need an example or step by step to correct. I am new to VB and hitting this wall and feel I'm so close. Thank you in advance for your help im really struggling here.

[代码]

严格启用选项

公共课程frmLocalWeather
   
   私有Sub btnSubmit_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理btnSubmit.Click
       '连接到Web服务以提供所选城市的天气,温度或两者兼而有之.
       
      昏暗的wsWeatherReturn作为新com.cdyne.wsf.Weather
      昏暗的wsWeather1作为新com.cdyne.wsf.WeatherReturn
      将intZipCode变暗为字符串
      昏暗的strTempType作为字符串
       Dim strWeatherType作为字符串

      试试

           intZipCode = Convert.ToString(txtZip.Text)
           wsWeather1 = wsWeatherReturn.GetCityWeatherByZIP("37066")

      将异常捕获为FormatException
           '检测信息是否丢失
           MsgBox(选择邮政编码和天气类型",错误")
      将异常捕获为OverflowException
           此捕获块检测到的数字大"
           MsgBox(请输入邮政编码")
      将异常捕获为SystemException
           此catch块检测到一般异常.")
           MsgBox(输入无效.请输入有效的邮政编码")
      结束尝试


       '选择天气或温度
      如果(cboWeather.SelectedIndex> -1)然后
           strTempType = CStr(cboWeather.SelectedIndex)
          试试
                            选择案例strTempType
                   案例CStr(0)
               b wsWeather1 = wsWeatherReturn.GetCityWeatherByZIP("37066")
               b strWeatherType ="温度"
                   案例CStr(1)
               b wsWeather1 = wsWeatherReturn.GetCityWeatherByZIP("37066")
               b strWeatherType ="天气"
                    Case CStr(2)
               b wsWeather1 = wsWeatherReturn.GetCityWeatherByZIP("37066")
               b strWeatherType ="两者都是"
                            结束选择
                             '产生天气或温度
                             LblForecast.Text = intZipCode.ToString& " " & strWeatherType
          将异常捕获为SystemException
                             MsgBox("Web服务不可用",错误")
          结束尝试
      其他
           MsgBox(选择邮政编码和天气类型")
      如果结束
   结束子


   私有Sub btnClear_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理btnClear.Click
       txtZip.Text =""
       LblForecast.Text =""
       cboWeather.Text =""

   结束子

   私有Sub btnExit_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理btnExit.Click
      关闭()
   结束子


   私有子目录frmLocalWeather_Load(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理MyBase.Load
       明确的预测标签
       LblForecast.Text =""

   结束子

结束类
[/code]

Option Strict On

Public Class frmLocalWeather
   
    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        'Connects to Web Services to give either the weather, temperature, or both for the selected City.
        
        Dim wsWeatherReturn As New com.cdyne.wsf.Weather
        Dim wsWeather1 As New com.cdyne.wsf.WeatherReturn
        Dim intZipCode As String
        Dim strTempType As String
        Dim strWeatherType As String

        Try

            intZipCode = Convert.ToString(txtZip.Text)
            wsWeather1 = wsWeatherReturn.GetCityWeatherByZIP("37066")

        Catch Exception As FormatException
            'Detects if information is missing
            MsgBox("Select a Zip and Weather Type", , "Error")
        Catch Exception As OverflowException
            'This catch Block detects numbers that are to Large
            MsgBox("Please enter Zip Code")
        Catch Exception As SystemException
            'This catch block detects a generic exception.")
            MsgBox("Entry invalid. Please enter a valid Zip Code")
        End Try


        'Select Weather or Temperature
        If (cboWeather.SelectedIndex > -1) Then
            strTempType = CStr(cboWeather.SelectedIndex)
            Try
                Select Case strTempType
                    Case CStr(0)
                        wsWeather1 = wsWeatherReturn.GetCityWeatherByZIP("37066")
                        strWeatherType = " Temperature "
                    Case CStr(1)
                        wsWeather1 = wsWeatherReturn.GetCityWeatherByZIP("37066")
                        strWeatherType = " Weather "
                    Case CStr(2)
                        wsWeather1 = wsWeatherReturn.GetCityWeatherByZIP("37066")
                        strWeatherType = " Both "
                End Select
                'Produce Weather or temp
                LblForecast.Text = intZipCode.ToString & " " & strWeatherType
            Catch Exception As SystemException
                MsgBox("Web Service Not Available", , "Error")
            End Try
        Else
            MsgBox("Select a Zip and Weather type")
        End If
    End Sub


    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtZip.Text = ""
        LblForecast.Text = ""
        cboWeather.Text = ""

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Close()
    End Sub


    Private Sub frmLocalWeather_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Clear Forecast Label
        LblForecast.Text = ""

    End Sub

End Class
[/code]

推荐答案

你好,

以前从未使用过,只是尝试了他们的服务.

Never used this before but just tried thier services.

  1. 为我的项目添加了新服务 http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL
  2. 编写一些代码
  1. Added a new service to my project http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL
  2. Wrote some code

        Dim ZipCode As String = "97303"
        Dim w As New WeatherService1.WeatherSoapClient()
        Dim ForcastTest = w.GetCityForecastByZIP(ZipCode)


        If ForcastTest.Success Then
            Console.WriteLine("{0},{1}", ForcastTest.City, ForcastTest.State)
            For Each Item In ForcastTest.ForecastResult
                Console.WriteLine("{0} {1}", Item.Date.ToShortDateString, Item.Desciption)
            Next

        End If

        Dim Citytest = w.GetCityWeatherByZIP(ZipCode)
        If Citytest.Success Then

            Console.WriteLine("Relative Humidity {0}", Citytest.RelativeHumidity)
        End If

结果

Salem,OR
3/22/2014 Sunny
3/23/2014 Sunny
3/24/2014 Sunny
3/25/2014 Showers
3/26/2014 Showers
3/27/2014 Showers
3/28/2014 Rain
RelativeHumidity 31

app.config中的端点

Endpoints in app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="WeatherSoap" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://wsf.cdyne.com/WeatherWS/Weather.asmx"
                binding="basicHttpBinding" bindingConfiguration="WeatherSoap"
                contract="WeatherService1.WeatherSoap" name="WeatherSoap" />
        </client>
    </system.serviceModel>
  <system.net>
    <defaultProxy useDefaultCredentials="true" />
  </system.net>
</configuration>


这篇关于天气网络服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆