liuwenliang的个人博客分享 http://blog.sciencenet.cn/u/liuwenliang

博文

web service 调用acobject问题集

已有 2446 次阅读 2019-12-27 12:00 |个人分类:arcobjects|系统分类:科研笔记

第一个问题:授权

在winform程序开发arcobjects程序时候,需要在Program.cs中写如如下代码授权:

[STAThread]

        static void Main()

        {

            Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);

            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);

            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);

            Application.Run(new frmSpatialBuffer());

        }

那么,在web service中调用AO,也存在这个授权问题,那在哪里授权呢。

正确答案是:在web sercice类得构造函数中,我的代码如下(参考了网络资料:https://community.esri.com/thread/63551),

public class Service : System.Web.Services.WebService

    {

        public Service()

        {

            //如果使用设计的组件,请取消注释以下行 

            //InitializeComponent(); 


            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);

            ESRI.ArcGIS.esriSystem.IAoInitialize aoInit = new ESRI.ArcGIS.esriSystem.AoInitializeClass();

            aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);//esriLicenseProductCodeEngine

        }



        [WebMethod]

        public string HelloWorld()

        {

            return "Hello World";

        }

}

上诉的两部分代码缺一不可,缺少哪个都会报错误。

如果缺少ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);

错误为:网页崩溃

image.png

如果

 ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);

            ESRI.ArcGIS.esriSystem.IAoInitialize aoInit = new ESRI.ArcGIS.esriSystem.AoInitializeClass();

            aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);//esriLicenseProductCodeEngine

都缺少:

image.png

授权代码这样处理后,在debug模式下运行没有问题。

但是如果发布到IIS访问,还会出以下问题。

第一个问题:

 "因 URL 意外地以 结束,请求格式无法识别" 的解决方法

按照https://www.cnblogs.com/AlphaThink-AT003/p/3880076.html的介绍,在web.config文件中的 <system.web>内加入

<webServices>

      <protocols>

        <add name="HttpGet"/>

        <add name="HttpPost"/>

        <add name="Unknown"/>

        <add name="HttpSoap"/>

      </protocols>

    </webServices>

即可。

第二个问题:

未能加载文件或程序集“XXXXXX”或它的某一个依赖项。试图加载格式不正确的程序。

将C#工程的framework改为.net 2.0,然后目标平台改为x86,

并将应用程序池的

IIS——应用程序池——高级设置——启用32位应用程序 :true。

参考:https://www.cnblogs.com/autumn/p/3575008.html



https://blog.sciencenet.cn/blog-3409972-1211691.html

上一篇:Web Service发布报错:HTTP 错误 500.19 - Internal Server Error
下一篇:[转载][ArcPy] 1 ArcPy与栅格(Raster)
收藏 IP: 210.72.26.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (3 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-7-18 18:37

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部