关于ArcGIS version not specified. You must call RuntimeManager.Bind的问题
小弟刚接触ASP.net 对此方面一片茫然。下面贴代码
public class Service1 : System.Web.Services.WebService
{
public static void Initialize()
{
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
Setting.Setting.initializeSetting(@"C:\Users\fkw\Desktop\SSite", @"Net");
}
[WebMethod]
/*将传入的四个数转换为doulbe然后将这个区域切割成数块小区域,再将每个区域的要素数量极其包含的FID
显示出来,返回给客户端*/
public XmlDocument sAmpling_bops(string str_x1, string str_y1, string str_x2, string str_y2,int SPLIT,double selectance)
{
IAoInitialize AO = new AoInitialize();
XmlDocument xml = new XmlDocument();
try
{
Initialize();
Setting.Setting.SPLIT_BOPS = SPLIT; List<int> repeat_ID = new List<int>();
AO.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
XmlNode root = xml.CreateNode(XmlNodeType.XmlDeclaration, "", "");
xml.AppendChild(root);
double x1 = Convert.ToDouble(str_x1);
double y1 = Convert.ToDouble(str_y1);
double x2 = Convert.ToDouble(str_x2);
double y2 = Convert.ToDouble(str_y2);
XmlElement node = xml.CreateElement("sampling");
xml.AppendChild(node);
IWorkspaceFactory wk_space = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace pFeatWS;
pFeatWS = wk_space.OpenFromFile(Setting.Setting.Pos_SITE + @"\Data", 0) as IFeatureWorkspace;
////打开一个要素类
IFeatureClass pFeatureClass = pFeatWS.OpenFeatureClass(Setting.Setting.Name_LAYER + ".shp");
///处理各个分割区间
double spacingY = (y2 - y1) / Setting.Setting.SPLIT_BOPS, spacingX = (x2 - x1) / Setting.Setting.SPLIT_BOPS;
List<int> List_ID = new List<int>();
for (int i = 0; i < Setting.Setting.SPLIT_BOPS; ++i)
{
for (int j = 0; j < Setting.Setting.SPLIT_BOPS; ++j)
{
#region
double[] Area = new double[4];
Area[0] = x1 + i * spacingX; Area[1] = y1 + spacingY * j;
Area[2] = Area[0] + spacingX; Area[3] = Area[1] + spacingY;
if (Area[2] > x2) Area[2] = x2;
if (Area[3] > y2) Area[3] = y2;
List_ID.Clear(); List_ID = Helper.Helper.getAreaNums(pFeatureClass, Area);///
if (List_ID.Count == 0) continue;
#endregion
string list_temp_Id = ""; int total = 0;
while (total++ < (int)List_ID.Count * selectance)
{
list_temp_Id = ""; int ID = -1; Random r = new Random();
do
{
ID = r.Next(List_ID.Count);
} while (repeat_ID.Contains(List_ID[ID])); repeat_ID.Add(List_ID[ID]);
IPointCollection pt_coll = pFeatureClass.GetFeature(List_ID[ID]).Shape as IPointCollection;
IPoint pt = null;
for (int k = 0; k < pt_coll.PointCount; ++k)
{
pt = pt_coll.get_Point(k);
list_temp_Id += pt.X.ToString() + "," + pt.Y.ToString() + ",";
}
list_temp_Id = list_temp_Id.Remove(list_temp_Id.Length - 1, 1);
XmlElement xml_elm = xml.CreateElement("INFOR");
xml_elm.InnerText = list_temp_Id;
node.AppendChild(xml_elm);
}
}
}
AO.Shutdown();
return xml;
}
catch (Exception ex)
{
AO.Shutdown();
if (Helper.Helper.Errors.Count != 0)
{
XmlElement error = xml.CreateElement("error");
error.SetAttribute("getAreaNums", Helper.Helper.Errors["getAreaNums"].ToString());
xml.ChildNodes.Item(1).AppendChild(error);
}
XmlElement error1 = xml.CreateElement("Exception");
error1.SetAttribute("error1", ex.Message.ToString());
xml.ChildNodes.Item(1).AppendChild(error1);
return xml;
}
}
}
}
上处是一个webservice,发现再使用的时候出现许可的问题。按网上的方法加了句代码还是不行
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
求大神来看一下