Windows Phone 7 使用 Web 服务 WSDL

发布于 2024-12-10 06:43:06 字数 2910 浏览 1 评论 0原文

好吧,我之前写过一些基本的通用 Web 服务,但我从未尝试过使用第 3 方服务。 我想消费的是 http://opendap.co-ops.nos .noaa.gov/axis/webservices/predictions/wsdl/Predictions.wsdl

我没有从中得到任何结果,也无法弄清楚找出原因。 更奇怪的是,当我在代码中放置断点时,它甚至没有达到 PredictionsClient_getPredictionsAndMetadataCompleted ,它甚至没有达到它。 任何建议将不胜感激

    public void Bouy(double meters)   
    {   
        PredictionService.Parameters PredictionParams = new PredictionService.Parameters();   
        PredictionService.PredictionsPortTypeClient PredictionsClient = new PredictionService.PredictionsPortTypeClient();   

        GeoCoordinateWatcher gc = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);   
        //gc.Position.Location.Latitude, gc.Position.Location.Longitude   
        GeoCoordinate myLocation = new GeoCoordinate(27.931631,-82.802582);   


        foreach (var bl in BouyLocation.GetAll())   
        {    
            GeoCoordinate otherLocation = new GeoCoordinate(bl.Lat, bl.Lon);   

                PredictionParams.beginDate = DateTime.Now.ToString("yyyyMMdd");   
                PredictionParams.endDate = DateTime.Now.AddDays(1.0).ToString("yyyyMMdd");   
                PredictionParams.stationId = bl.LocationID;   
                PredictionParams.timeZone = 0;   
                PredictionParams.unit = 1;   
                PredictionParams.dataInterval = 6;   
                PredictionsClient.getPredictionsAndMetadataCompleted += new EventHandler<PredictionService.getPredictionsAndMetadataCompletedEventArgs>(PredictionsClient_getPredictionsAndMetadataCompleted);   

                PredictionsClient.getPredictionsAndMetadataAsync(PredictionParams);   


            double mymeters = myLocation.GetDistanceTo(otherLocation);   
            if (mymeters < meters)   
            {   
                TextBlock DynTextBlock = new TextBlock   
                {   
                    Name = "Appearance" + bl.LocationID,   
                    Text = bl.LocationName + PredictionResult,   
                    TextWrapping = System.Windows.TextWrapping.Wrap,   
                    Margin = new Thickness(12, -6, 12, 0),   
                    Style = (Style)Resources["PhoneTextSubtleStyle"]   

                };   

                DynamicAppearance.Children.Add(DynTextBlock);   
                this.nearByLocations.Add(new BouyLocationModel() { LocationName = bl.LocationName, LocationID = bl.LocationID, Lat = bl.Lat, Lon = bl.Lon });   
            }   
        }   
        var test = nearByLocations;   
    }   

    void PredictionsClient_getPredictionsAndMetadataCompleted(object sender, PredictionService.getPredictionsAndMetadataCompletedEventArgs e)   
    {   
        string err = e.Error.ToString();   

        PredictionResult = e.Result.ToString();   
    }  

Ok I have written some basic generic webservices before but I have never tried to consume a 3rd party one.
The one I am trying to consume is
http://opendap.co-ops.nos.noaa.gov/axis/webservices/predictions/wsdl/Predictions.wsdl

I am not getting any results back from this what so ever and cannot figure out why.
More odd is it is not even reaching PredictionsClient_getPredictionsAndMetadataCompleted when I put a break point in the code it doesn't even reach it.
Any suggestions would be greatly appreciated

    public void Bouy(double meters)   
    {   
        PredictionService.Parameters PredictionParams = new PredictionService.Parameters();   
        PredictionService.PredictionsPortTypeClient PredictionsClient = new PredictionService.PredictionsPortTypeClient();   

        GeoCoordinateWatcher gc = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);   
        //gc.Position.Location.Latitude, gc.Position.Location.Longitude   
        GeoCoordinate myLocation = new GeoCoordinate(27.931631,-82.802582);   


        foreach (var bl in BouyLocation.GetAll())   
        {    
            GeoCoordinate otherLocation = new GeoCoordinate(bl.Lat, bl.Lon);   

                PredictionParams.beginDate = DateTime.Now.ToString("yyyyMMdd");   
                PredictionParams.endDate = DateTime.Now.AddDays(1.0).ToString("yyyyMMdd");   
                PredictionParams.stationId = bl.LocationID;   
                PredictionParams.timeZone = 0;   
                PredictionParams.unit = 1;   
                PredictionParams.dataInterval = 6;   
                PredictionsClient.getPredictionsAndMetadataCompleted += new EventHandler<PredictionService.getPredictionsAndMetadataCompletedEventArgs>(PredictionsClient_getPredictionsAndMetadataCompleted);   

                PredictionsClient.getPredictionsAndMetadataAsync(PredictionParams);   


            double mymeters = myLocation.GetDistanceTo(otherLocation);   
            if (mymeters < meters)   
            {   
                TextBlock DynTextBlock = new TextBlock   
                {   
                    Name = "Appearance" + bl.LocationID,   
                    Text = bl.LocationName + PredictionResult,   
                    TextWrapping = System.Windows.TextWrapping.Wrap,   
                    Margin = new Thickness(12, -6, 12, 0),   
                    Style = (Style)Resources["PhoneTextSubtleStyle"]   

                };   

                DynamicAppearance.Children.Add(DynTextBlock);   
                this.nearByLocations.Add(new BouyLocationModel() { LocationName = bl.LocationName, LocationID = bl.LocationID, Lat = bl.Lat, Lon = bl.Lon });   
            }   
        }   
        var test = nearByLocations;   
    }   

    void PredictionsClient_getPredictionsAndMetadataCompleted(object sender, PredictionService.getPredictionsAndMetadataCompletedEventArgs e)   
    {   
        string err = e.Error.ToString();   

        PredictionResult = e.Result.ToString();   
    }  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

优雅的叶子 2024-12-17 06:43:06

看看您这里的代码,我认为您已经使用 ServiceReference 的导入来自动为您构建类?

不幸的是,我发现这在 WP7 上相当不稳定,而我真正让它工作的唯一方法是将它连接到 Microsoft WCF 服务。连接到其他任何东西都不起作用。

如果你进行谷歌搜索,就会有各种页面谈论它不起作用的事实以及解决它的方法(我无法开始工作)。

然而,有很多方法可以解决这个问题,但它并不像自动生成的东西那么简单。基本上你手动做事。

尽管还有其他方法可以手动创建 Web 服务,但我所做的是遵循以下有效的信息: http://zetitle.wordpress.com/2010/10/14/using-reactive-extensions-with-webrequest/

您需要自己解析响应,但 XML to LINQ 对此非常有效。

希望有帮助,或者也许有人会找到解决方案,因为我也有兴趣知道如何开始工作

Loooking at the code you have here I think that you have used the importing of a ServiceReference to auto build the classes for you?

Unfortunately I have found that this is rather temperamental on WP7 and the only way I actually got it to work was when I connected it to a Microsoft WCF service. Connecting to anything else just doesn't work.

If you do google searches there are various pages talking about the fact it doesn't work and ways around it (which I couldn't get to work).

However, there are ways around it but it isn't as simple as the auto-generated stuff. Basically you do things manually.

Although there are other ways to manually create the web service what I did was follow the information in the following which worked well: http://zetitle.wordpress.com/2010/10/14/using-reactive-extensions-with-webrequest/

You will need to parse the response yourself but XML to LINQ works really well for this.

Hope that helps, or maybe someone will have the solution as it is something I am interested in knowing how to get working too

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文