我在我的 .net Web 应用程序中使用 bing soap 服务,我得到“对象引用未设置为对象的实例”。第 74 行中的错误:
Line 72: geom p=null;
Line 73: string k = input.country + ", " + input.zipCode;
Line 74: x = p.GeocodeAddress(k); // HERE
Line 75: input.lat = x.Latitude;
Line 76: input.lng = x.Longitude;
类代码如下:
using thn.GeocodeService;
public class geom
{
public Location GeocodeAddress(string inputAddress)
{
GeocodeRequest geocodeRequest = new GeocodeRequest();
geocodeRequest.Credentials = new GeocodeService.Credentials();
geocodeRequest.Credentials.ApplicationId = "<my bing code>";
geocodeRequest.Query = inputAddress;
GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);
if ((geocodeResponse.Results.Length > 0) && (geocodeResponse.Results[0].Locations.Length > 0))
{
return geocodeResponse.Results[0].Locations[0];
}
else
{
return null;
}
}
}
调用部分如下:
user input;
Location x;
geom p=null;
string k = input.country + ", " + input.zipCode;
x = p.GeocodeAddress(k);
input.lat = x.Latitude;
input.lng = x.Longitude;
现在我哪里错了?而且我已经将地理编码服务添加到我的项目的服务参考中,所以这不是问题..