.net 使用bing maps SOAP服务时发生对象引用错误
可能重复:.net 使用bing maps SOAP服务时发生对象引用错误,.net,soap,bing-maps,object-reference,.net,Soap,Bing Maps,Object Reference,可能重复: 我在我的.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: in
我在我的.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;
我哪里会错呢?我还将地理编码服务添加到项目的服务引用中,因此这不是问题。您需要创建geom类的新实例。您没有实例化p。p是空的。 试一试
geom p=新的geom();
欢迎来到堆栈溢出!几乎所有NullReferenceException的情况都是相同的。请参阅“”以获得一些提示。真的吗?您的代码基本上是geom p=null;x=p.GeocodeAddress(k)代码>。这与执行x=null.GeocodeAddress(k)相同代码>。这与必应地图毫无关系!