Bing GeocodeService userState用法作为自定义附加参数 [英] Bing GeocodeService userState usage as custom additional parameter

查看:88
本文介绍了Bing GeocodeService userState用法作为自定义附加参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows Phone 7.1应用程序中,我必须发送一个使用Bing地理编码服务的请求(使用地址:

In my Windows Phone 7.1 application I have to send a request that consumes Bing geocoding services (using the address: http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc/mex, without setting the option Always generate message contracts in my Service Reference Settings).

我的请求是通过以下方式发出的:

My request is made in this way:

BingMapGeoCodeService.GeocodeRequest request = new BingMapGeoCodeService.GeocodeRequest();

request.Options = new BingMapGeoCodeService.GeocodeOptions()
{
    Filters = new ObservableCollection<BingMapGeoCodeService.FilterBase>()
    {
        new BingMapGeoCodeService.ConfidenceFilter() { MinimumConfidence = BingMapGeoCodeService.Confidence.High}
    }
};

request.Credentials = ( ...my credentials... )

request.Address = new BingMapGeoCodeService.Address()
{
    AddressLine = String.IsNullOrEmpty(address) ? null : address.Trim(),
    Locality = String.IsNullOrEmpty(city) ? null : city.Trim(),
    PostalCode = String.IsNullOrEmpty(zipCode) ? null : zipCode.Trim()
};

...现在我必须以这种方式发送异步请求:

...now I have to send my async request, in this way:

geocodeServiceClient.GeocodeAsync(request);

一切正常,但是我有一个小问题(当然,有很多解决方法...但是我想以最好的方式来做!):我想根据我的要求发送另外一个当我从服务器获取响应时将使用的参数(在我的情况下,它只是一个Guid标识符,但也可以是一个String值!)(

It all works fine, but I have a little problem (of course there a lot of workarounds...but I would like to do it in the best way!): I want to send, in my request, an additional parameter (in my case it's just a Guid identifier, but also a String value would be ok!) that I would use when I get the response from the server (I need it for another internal check):

private void geocodeServiceClient_GeocodeCompleted(object sender, BingMapGeoCodeService.GeocodeCompletedEventArgs e)
{
    // HERE I WANT TO GET BACK MY VALUE, TO CHECK IT!  

    var geoResult = (from r in e.Result.Results
                     orderby (int)r.Confidence ascending
                     select r).FirstOrDefault();

    ... some more logic here ...
}

我进行了搜索,但是,由于(我认为)缺乏文档,我发现了GeocodeAsync()方法的这个附加参数:

I searched around but, also because (in my opinion) of a lack of documentation, I found out this additional parameter of the GeocodeAsync() method:

geocodeServiceClient.GeocodeAsync(request, userState);

我可以使用此参数作为我的请求的自定义附加参数吗?

Can I use this parameter as a custom additional parameter for my request?

将额外的参数传递给第三方服务是否正确?

Is it the correct way to pass an extra parameter to third-part services?

万一这样做不好:这种重载的含义和用途是什么?

In case it's not good to do so: what's the meanining and the usage of this overload?

为什么这样称呼(我的意思是 userState )?

And why is it called so (I mean userState)?

非常感谢您!

推荐答案

我终于找到了自己的方式:userState参数是我要搜索的内容.

I finally found my own way: userState parameter is what I was searching for.

按照以下有关WCF服务的问题进行操作: http://www.c-sharpcorner.com/uploadfile/prvn_131971/chapter-33-advanced-web-services/

Follow this question about WCF Services: http://www.c-sharpcorner.com/uploadfile/prvn_131971/chapter-33-advanced-web-services/

这篇关于Bing GeocodeService userState用法作为自定义附加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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