usted puede utilizar arcobjects en un MVC servicio (o cualquier servicio para el caso) siempre y cuando el / los servicio(s) residen en el mismo servidor como Servidor de ArcGIS. El Uso De ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.Código de producto.Servidor) y ... serverStatus = ao.Inicializar(esriLicenseProductCode.esriLicenseProductCodeArcServer);
public HttpResponseMessage Post([FromBody] List<ModelRequest> requests)
{
//request not getting through
//verify TrowIfMaxHttpCollectionKeysExceeded
//limits the amount of collections sent (default 1000) overide with below.
//<appSettings>
//<add key="aspnet:MaxHttpCollectionKeys" value="1001" />
//</appSettings>
if (requests == null)
{
return CreateResponseMessage(HttpStatusCode.InternalServerError, "Unhandled Exception", "Request Is Null");
}
HttpResponseMessage returnMessage = CreateResponseMessage(HttpStatusCode.InternalServerError, "Unhandled Exception", "Task Failed"); ;
var sta = new StaTaskScheduler(numberOfThreads: 1);
var task = Task.Factory.StartNew(() =>
{
//do work in sta thread
returnMessage = DoWork(requests);
}, CancellationToken.None, TaskCreationOptions.None, sta);
Task.WaitAll(task);
return returnMessage;
}
private HttpResponseMessage DoWork(List<ModelRequest> requests)
{
//now in StaThread
string staVerify = Thread.CurrentThread.GetApartmentState().ToString();
//Do ArcObjects coding here... make sure ALL arcobjects are created in the
//StaThread. Watch out for member level variables that are created in static
//classes for example.
return Request.CreateResponse(HttpStatusCode.OK, myModelResults, "application/json");
}
/// <summary>
/// Create an HTTP custom response.
/// </summary>
/// <param name="code">HTTP Status Code</param>
/// <param name="title">title of response message.</param>
/// <param name="content">response message content.</param>
/// <returns>HttpResponseMessage</returns>
private HttpResponseMessage CreateResponseMessage(HttpStatusCode code, string title, string content)
{
var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
Content = new StringContent(content),
ReasonPhrase = title
};
return resp;
}