Saturday 26 August 2017

arcgis server - ESRI: ADF + Geodatabase


I'm a .NET Develop. I'm using ESRI / ADF and I have a problem whit some methods of Geodatabase. On the beginning of development I needed connect on GeoDB and execute queries. On this moment I got this error, ACCESS DENIED:


(Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))



So I solved this, creating my IWorkspace object through ServerContext property in the connection object.


In other step of development I needed resolve some relations. Through the IObject I got the IEnumRelationshipClass then, I got IRelationshipClass object to resolve the relation. The object IRelationshipClass give me some methods:


1) GetObjectsRelatedToObject(expects a IObject) returns a ISet with all related objects from the object;


2) GetObjectsRelatedToObjectSet(expects a ISet) returns a ISet with all related objects from the ISet with OBJECTID or IObject;


3) GetObjectsMatchingObjectSet(expects a ISet) returns a IRelClassEnumRowPairs (I don't now how use this method or his purpose, so, I don't use this method)


When I'm using the method (1), I don't get the error, but when I'm try to use the others methods, I had the same error, access is denied.


I tryed everything, add all references, using the IAoInitialize for start the ESRI license, set the access and authorizations on the ArgGIS Server. Give access to ArcSOM, ArcSOC on some COM objects through de MMC.


To connect in GeoDB I'm using a GeoDatabaseService with ArcGIS Web Service.


Here some pieces of the code:


<---Connection--->



        internal bool DoOpenAuthenticateConnection()
{
Identity identity = null;
IServerObjectManager icServerObjectManager = null;
IGeoDataServer icGeoDataServer = null;
IGeoDataServerObjects icGeoDataServerObjects = null;

try
{
this.Initialize();


if (IsCon())
return true;

using (ComReleaser comReleaser = new ComReleaser())
{
identity = new Identity(Authentication.User, Authentication.Password, Authentication.Domain);
comReleaser.ManageLifetime(identity);

Connection = new AGSServerConnection(Host, identity, true);

comReleaser.ManageLifetime(Connection);

icServerObjectManager = Connection.ServerObjectManager;
comReleaser.ManageLifetime(icServerObjectManager);

//this is a property of class GObjectClass, I use this to create the IWorkspace...
this.GIServerContext = icServerObjectManager.CreateServerContext(NomeServico, TipoServico);

icGeoDataServer = this.GIServerContext.ServerObject as IGeoDataServer;
comReleaser.ManageLifetime(icGeoDataServerObjects);


icGeoDataServerObjects = icGeoDataServer as IGeoDataServerObjects;
comReleaser.ManageLifetime(icGeoDataServer);

//I use this to create get accessibility to GeoDB.
this.GIWorkspace = icGeoDataServerObjects.DefaultWorkingWorkspace;

this.DoSchemaResolve();
this.DoResolveDomain();


return true;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
GReleaseComObject.ReleaseComObject(identity);

GReleaseComObject.ReleaseComObject(Connection);
GReleaseComObject.ReleaseComObject(icServerObjectManager);
GReleaseComObject.ReleaseComObject(icGeoDataServer);
GReleaseComObject.ReleaseComObject(icGeoDataServerObjects);
}
}

<---Relates--->


internal void DoResolveRelationshipClass(IObject[] icObjects, bool resolveDomain, ref DataSet dataSet, ref GListFieldDataset gListFieldDataset, params string[] RelationshipClassName)
{

IEnumRelationshipClass icEnumRelationshipClass = null;
IRelationshipClass icRelationshipClass = null;

DataTable dataTable = null;
GListFieldTable gListFieldTable = null;

try
{
//for com os objeto com todos os relate
if (icObjects == null)

return;

if (icObjects.Length < 1)
return;

using (ComReleaser comReleaser = new ComReleaser())
{
//get first object, other objects has the same type.
icEnumRelationshipClass = icObjects[0].Class.get_RelationshipClasses(esriRelRole.esriRelRoleAny);
comReleaser.ManageLifetime(icEnumRelationshipClass);


while ((icRelationshipClass = icEnumRelationshipClass.Next()) != null)
{
if (RelationshipClassName != null && RelationshipClassName.Length > 0)
if (!DoFindRelateshipClass(DoRelationshipClassName(icRelationshipClass), RelationshipClassName))
continue;

if (dataSet != null)
dataTable = new DataTable();


if (gListFieldDataset != null)
gListFieldTable = new GListFieldTable();


//resolver todas as linhas no relate
this.DoResolveRelationshipClass(icObjects, icRelationshipClass, resolveDomain, ref dataTable, ref gListFieldTable);

if (dataTable != null)
dataSet.Tables.Add(dataTable);


if (gListFieldTable != null)
gListFieldDataset.Add(gListFieldTable);
}
}

}
catch (Exception ex)
{
throw ex;
}

finally
{
icEnumRelationshipClass = null;
icRelationshipClass = null;
}
}

internal void DoResolveRelationshipClass(IObject[] icObjects, IRelationshipClass icRelationshipClass, bool resolveDomain, ref DataTable dataTable, ref GListFieldTable gListFieldTable)
{
ISet icSet = null;

IObject icObjectResult = null;
ISet icSetFull = null;
string relateionshipClassName = string.Empty;

try
{
if (icObjects == null)
throw new ArgumentNullException("The parameter icFeature can't be null.");

using (ComReleaser comReleaser = new ComReleaser())

{
relateionshipClassName = DoRelationshipClassName(icRelationshipClass);

icSetFull = new SetClass();
comReleaser.ManageLifetime(icSetFull);

for (int i = 0; i < icObjects.Length; i++)
{
icSet = icRelationshipClass.GetObjectsRelatedToObject(icObjects[i] as IObject);
comReleaser.ManageLifetime(icSet);


icSet.Reset();

while ((icObjectResult = icSet.Next() as IObject) != null)
{
comReleaser.ManageLifetime(icObjectResult);
icSetFull.Add(icObjectResult);
}

icSet = null;

}

if (dataTable != null)
dataTable = DoObjectToDataTable(relateionshipClassName, icSetFull, icRelationshipClass, resolveDomain);

if (gListFieldTable != null)
gListFieldTable = DoObjectToListFieldTable(relateionshipClassName, icSetFull, icRelationshipClass, resolveDomain);
}
}
catch (Exception ex)

{
throw ex;
}
finally
{
icRelationshipClass = null;
icSet = null;
icSetFull = null;
icObjectResult = null;


}
}


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...