Using ArcObjects in standard web service

4329
10
Jump to solution
11-21-2012 01:08 PM
XintaoLiu
Occasional Contributor II
Dear All,

I created a standard web service using C# VS 2010. The operating system is Windows 7 and IIS version is 7. I added ArcGIS references to the C# web service project and tried to do: IAoInitialize m_pAoInit = new AoInitialize(). It can be done. But when I tried: IPoint p = new PointClass();

Then I got the following error:
Retrieving the COM class factory for component with CLSID {00A5CB41-52DA-11D0-A8F2-00608C85EDE5} failed due to the following error: 80040111 ClassFactory cannot supply requested class (Exception from HRESULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE)).

Any suggestion? Thanks in advance!
0 Kudos
1 Solution

Accepted Solutions
XintaoLiu
Occasional Contributor II
Thanks! Besides the settings in C# project and IIS, I also need to change license initialization codes as follows:

ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
IAoInitialize m_AOInit = new AoInitializeClass();
esriLicenseStatus  licenseStatus = m_AOInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);

Then the whole thing begins to work!

View solution in original post

0 Kudos
10 Replies
XintaoLiu
Occasional Contributor II
I tried to initialize the license:
       public WebService1()
        {           
            IAoInitialize m_AoInitialize = new AoInitializeClass();

            esriLicenseStatus status = m_AoInitialize.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeStandard);
        }

But there was no response when run to the second sentence. I just could not figure out whether ArcObjects can be used in a standard web service. Any of your reply is highly appreciated.
0 Kudos
RichardWatson
Frequent Contributor
0 Kudos
XintaoLiu
Occasional Contributor II
If you are using 10.0 or 10.1:

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//00460000002w000000


Thanks a lot! It works! My C# codes are as follows:
if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop))
                return "";
IAoInitialize aoInit = new AoInitializeClass();
aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);

However, when I publish the web service project to IIS, the web service can not be loaded. I am confused again. Any of your suggestion is highly appreciated.
0 Kudos
RichardWatson
Frequent Contributor
If your web service is x64 then you have to bind and license to ArcGIS Server.  Desktop is strictly 32 bit, i.e. x86.
0 Kudos
XintaoLiu
Occasional Contributor II
If your web service is x64 then you have to bind and license to ArcGIS Server.  Desktop is strictly 32 bit, i.e. x86.


Thank you so much! Yes, I have changed my C# project to x86, and the target .Net Framework to 2.0. Inside IIS at the server level, the ISApi and CGI is set to allow ASP.Net 2.0.

To my surprise, in debugging mode, everything runs smoothly. I can use ArcObjects to develop powerful tools for web service to consume. But, when try to publish it, the same problem occurs again. That is, if I put the following codes at the beginning, the webservice cannot be loaded, and there is not any responses:

if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop))
return "";
IAoInitialize aoInit = new AoInitializeClass();
aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
0 Kudos
RichardWatson
Frequent Contributor
I suspect that you have not configured your web service to run as x86, i.e. 32 bits only.
0 Kudos
XintaoLiu
Occasional Contributor II
I suspect that you have not configured your web service to run as x86, i.e. 32 bits only.


Thanks a million for your patience. I really appreciate that!

I capture the settings of my C# project the the IIS on Windows 7 computer (please see attached picture). When I test the project in debugging mode, that is, using the Visual Studio Development Server, something like http://localhost:55722/myArcObjectSvc.asmx, everything works fine. I can create ArcObjects and connect Oracle via ArcSDE. But, When I public the service to IIS, the service cannot run.

Thank you again.

[ATTACH=CONFIG]19494[/ATTACH]
0 Kudos
RichardWatson
Frequent Contributor
Just Google on "Windows 7 IIS 32 bit".  Here is one link which discusses this:

http://www.codeproject.com/Tips/325824/Running-a-32-bit-application-under-IIS-on-a-64-bit
0 Kudos
XintaoLiu
Occasional Contributor II
Thanks! Besides the settings in C# project and IIS, I also need to change license initialization codes as follows:

ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
IAoInitialize m_AOInit = new AoInitializeClass();
esriLicenseStatus  licenseStatus = m_AOInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);

Then the whole thing begins to work!
0 Kudos