# Can you use ArcObjects in an MVC service at v10.1

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?

-
Not a server developer myself, but I believe that SOEs are the only entry point to ArcObjects at Server 10.1: resources.arcgis.com/en/help/main/10.1/index.html#//… –  blah238 Jan 22 '13 at 15:56

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<ModelRequest> requests)
{
//request not getting through
//verify TrowIfMaxHttpCollectionKeysExceeded
//limits the amount of collections sent (default 1000) overide with below.
//<appSettings>
//</appSettings>
if (requests == null)
{
return CreateResponseMessage(HttpStatusCode.InternalServerError, "Unhandled Exception", "Request Is Null");
}

HttpResponseMessage returnMessage = CreateResponseMessage(HttpStatusCode.InternalServerError, "Unhandled Exception", "Task Failed"); ;

{
returnMessage = DoWork(requests);

return returnMessage;

}

private HttpResponseMessage DoWork(List<ModelRequest> requests)
{

//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;
}

-
Don't you need to do something to make it run on an STAThread? –  Kirk Kuykendall Feb 28 '13 at 23:41
Seems like something like this would be needed to assure it's on an STAThread. –  Kirk Kuykendall Mar 1 '13 at 3:06
I am using the STATaskScheduler and seems to work like a charm. –  Justin Carasick Apr 23 '13 at 14:48
The STATaskScheduler looks very useful ... could you post code snippet showing how you're using it? At least mention it in your answer. Google will find it there - but not in the comments section (or so I'm told). Googling for STATaskScheduler and Arcobjects only turns up this. –  Kirk Kuykendall Apr 23 '13 at 14:58
Code below. not sure if I added it right so it's picked up by Google. it's not very complex as you can see. Actually the ThrowIfMaxHttpCollectionKeysExceeded was a bigger pain but left that in too. –  Justin Carasick Apr 23 '13 at 23:01