Bing GeocodeService userState usage as custom additional parameter

守給你的承諾、 提交于 2019-12-23 05:55:07

问题


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);

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 ...
}

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?

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

Thank you very much in advance!


回答1:


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

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



来源:https://stackoverflow.com/questions/12176217/bing-geocodeservice-userstate-usage-as-custom-additional-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!