Using Geoprocessing in a service cause exception.

860
1
Jump to solution
07-23-2017 09:00 PM
ChangGuo
New Contributor

I 've created a Toolbox tool in ArcMap. It's a very simple tool designed to clip raster data. It works fun in ArcMap. And I used it in a console application. Here is the code:

ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
Geoprocessor gp = new Geoprocessor();
gp.AddToolbox(@"D:\Documents\ArcGIS\clipEnvelope\clipService.tbx");
gp.OverwriteOutput = true;
string rectangle = "94736.18 17841.65 97550.74 20512.60";
IVariantArray parameters = new VarArrayClass();
parameters.Add(rectangle);
gp.Execute("clipRaster", parameters, null);

The tool receive a envelope as parameter and "rectangle" in the code represent a envelope. The code works fun in console application. I used the same code in a ASP.NET Web application. And I received a COMException at the row "gp.Execute("clipRaster", parameters, null);".
Here is the detail of the exception:

用户代码未处理 System.Runtime.InteropServices.COMException
HResult=-2147417851
Message=The server threw an exception。 (Exception from HRESULT:0x80010105 (RPC_E_SERVERFAULT))
Source=ESRI.ArcGIS.Geoprocessing
ErrorCode=-2147417851
StackTrace:
在 ESRI.ArcGIS.Geoprocessing.GeoProcessorClass.Execute(String Name, IVariantArray ipValues, ITrackCancel pTrackCancel)
在 ESRI.ArcGIS.Geoprocessor.Geoprocessor.Execute(String name, IVariantArray parameters, ITrackCancel trackCancel)
在 TINServiceTest.TINService.HelloWorld() 位置 d:\VS workspace\TINServiceTest\TINServiceTest\TINService.asmx.cs:行号 41
InnerException:

I am developing a ASP.NET Web application. So how can I solve the problem? I would be very grateful for the help.

0 Kudos
1 Solution

Accepted Solutions
YuanLiu
Occasional Contributor

You would need to initialize Server license, instead of Engine or Desktop, in your code since it is a web application (http://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#aoinitialize.htm ). Engine and Desktop license are one user per license mode.

Just FYI, it's not really recommended to use ArcObjects SDK in ASP.NET web applications. Server Object Extension would be a better option to use ArcObjects in web environment (http://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#652a31ce-4f02-43b5-bba9-9db26ce231af... ). 

View solution in original post

0 Kudos
1 Reply
YuanLiu
Occasional Contributor

You would need to initialize Server license, instead of Engine or Desktop, in your code since it is a web application (http://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#aoinitialize.htm ). Engine and Desktop license are one user per license mode.

Just FYI, it's not really recommended to use ArcObjects SDK in ASP.NET web applications. Server Object Extension would be a better option to use ArcObjects in web environment (http://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#652a31ce-4f02-43b5-bba9-9db26ce231af... ). 

0 Kudos