关于ArcGIS version not specified. You must call RuntimeManager.Bind的问题

qq_29422245 2017-03-07 04:16:21
小弟刚接触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);
求大神来看一下
...全文
207 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_29422245 2017-03-07
  • 打赏
  • 举报
回复
顶~~~~~~~~

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧