I'm slighlty confused with the changes at 10.1 and understand this version no longer supports DCOM or remote arcobjects.
Can you use ArcObjects in a webservice (in my case a .NET MVC 4 service) that is deployed on the ArcGIS Server host (so not remote) and uses ArcObjects to perform editing on a gdb featureclass?
Or is the only way to go through the SOE framework?
If you can use ArcObjects in the .NET MVC service are there any ramifications of doing so over using an SOE?
Answer
you can use arcobjects in an MVC service (or any service for that matter) as long as the service(s) reside on the same server as ArcGIS Server. Use ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Server)) and ... serverStatus = ao.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);
public HttpResponseMessage Post([FromBody] List requests)
{
//request not getting through
//verify TrowIfMaxHttpCollectionKeysExceeded
//limits the amount of collections sent (default 1000) overide with below.
//
//
//
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 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");
}
///
/// Create an HTTP custom response.
///
/// HTTP Status Code
/// title of response message.
/// response message content.
/// HttpResponseMessage
private HttpResponseMessage CreateResponseMessage(HttpStatusCode code, string title, string content)
{
var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
Content = new StringContent(content),
ReasonPhrase = title
};
return resp;
}
No comments:
Post a Comment