私の Windows Phone 7.1 アプリケーションでは、Bing ジオコーディング サービスを使用する要求を送信する必要があります (アドレス: http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc/mexを使用して、オプションを設定せずAlways generate message contracts
にサービス参照設定)。
私のリクエストは次のように行われます。
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()
};
...次の方法で、非同期リクエストを送信する必要があります。
geocodeServiceClient.GeocodeAsync(request);
それはすべて正常に動作しますが、少し問題があります (もちろん、回避策はたくさんあります... しかし、最善の方法でそれを行いたいと思います!): リクエストで、追加のパラメーター (私の場合、それは単なるGuid
識別子ですが、String
値でも問題ありません!) サーバーから応答を受け取るときに使用します (別の内部チェックに必要です):
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()
メソッドの次の追加パラメーターを見つけました。
geocodeServiceClient.GeocodeAsync(request, userState);
このパラメーターをリクエストのカスタム追加パラメーターとして使用できますか?
サードパーティのサービスに追加のパラメーターを渡すのは正しい方法ですか?
そうするのが良くない場合: このオーバーロードの意味と使用法は何ですか?
なぜそう呼ばれているのですか(つまり userState)?
事前にどうもありがとうございました!