Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 使用bing maps SOAP服务时发生对象引用错误_.net_Soap_Bing Maps_Object Reference - Fatal编程技术网

.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)相同。这与必应地图毫无关系!