How to connect to GIS server using WCF igisserverconnection

Source: Internet
Author: User

I encountered a strange problem when I was writing WCF during this time. After I published the WCF to IIS, igisserverconnection. connet would never be able to connect. The specific error is as follows:

Error Type: connection to the server; error Description: Access denied. (Exception from hresult: 0x80070005 (e_accessdenied ))
Server stack trace: In system. servicemodel. channels. servicechannel. throwiffaultunderstood (Message reply, messagefault fault, string action, messageversion version, faultconverter) In system. servicemodel. channels. servicechannel. handlereply (proxyoperationruntime operation, proxyrpc & RPC) In system. servicemodel. channels. servicechannel. Call (string action, Boolean oneway, proxyoperationruntime operation, object [] INS, object [] outs, timespan timeout) In system. servicemodel. channels. servicechannelproxy. invokeservice (imethodcallmessage methodcall, proxyoperationruntime Operation) In system. servicemodel. channels. servicechannelproxy. Invoke (iMessage message)
Exception rethrown at [0]: In system. runtime. remoting. proxies. realproxy. handlereturnmessage (iMessage reqmsg, iMessage retmsg) In system. runtime. remoting. proxies. realproxy. privateinvoke (messagedata & msgdata, int32 type) In idciplservice. ff ()

In dciplserviceclient. ff () 

 

It is strange that no error will be reported if vs can be connected directly. During this period, all the methods mentioned on the Internet have been tried and still fail. Later, I switched to the ADF to connect and no error was reported.

 

 

To make use of ArcObjects via ArcGIS Server in your application, you must connect directly to the GIS server, which requires network access to the server Object Manager (SOM ).

ArcGIS Server connection objects

You can connect to a GIS server using the ArcGIS Server Library (ESRI. ArcGIS. Server) Or the ArcGIS Connection Library (ESRI. ArcGIS. ADF. Connection).

the server library connects to the GIS server through the gisserverconnection object. the gisserverconnection Object supports a single interface (in addition to iunknown ): igisserverconnection . igisserverconnection has a connect method that connects the application to the GIS server. the gisserverconnection Object provides connections to the GIS server and access to the serverobjectmanager and serverobjectadmin objects. the identity of the connecting user is not explicitly defined. instead, the identity of the application is used.

TheGisserverconnectionclassIs A. Net generated wrapper forGisserverconnectionCOM object.

[C #]
 
ESRI. arcGIS. server. gisserverconnectionclass gisconnection; gisconnection = new ESRI. arcGIS. server. gisserverconnectionclass (); gisconnection. connect ("localhost"); ESRI. arcGIS. server. iserverobjectmanager som = gisconnection. serverobjectmanager;

The Connection Library is a native. net assembly with the same connection capabilities as the server library, plus some additional management options. in most cases, you should use the Connection Library to connect to ArcGIS Server. it connects to the GIS server through the agsserverconnection class in the ESRI. arcGIS. ADF. connection assembly. the Connection Library also contains a connectionmanager class to manage fail-over and round-robin capabilities within the client. see the section titled using the Connection Manager for more information.

[C #]
 
ESRI. arcGIS. ADF. identity identity = new ESRI. arcGIS. ADF. identity ("user", "passwd", "Domain"); ESRI. arcGIS. ADF. connection. AGS. agsserverconnection agsconnection; agsconnection = new ESRI. arcGIS. ADF. connection. AGS. agsserverconnection ("hostname", identity); agsconnection. connect (); iserverobjectmanager som = agsconnection. serverobjectmanager;
[VB. NET]
Dim identity as ESRI. arcGIS. ADF. identity = new ESRI. arcGIS. ADF. identity ("user", "passwd", "Domain") dim ags_onnection as ESRI. arcGIS. ADF. connection. AGS. agsserverconnection agsconnection = new ESRI. arcGIS. ADF. connection. AGS. agsserverconnection ("hostname", identity) agsconnection. connect dim SOM as iserverobjectmanager = agsconnection. serverobjectmanager

Connecting to the GIS server: Security

For a client application to connect to ArcGIS Server, the application must be running as an operating system user that is a member of one of the following two operating system user groups defined on the ArcGIS Server machines: The ArcGIS Server users group (Agsusers) Or ArcGIS Server Administrators Group (Agsadmin). If the user the application is running as is not a member of either of those groups, thenConnectWill return an error.

In addition toConnectMethod,IgisserverconnectionInterface has two properties:ServerobjectmanagerAndServerobjectadmin. If the application is running as a user in the users or Administrators Group, the application can accessServerobjectmanagerProperty, which returnsIserverobjectmanagerInterface.IserverobjectmanagerInterface provides methods for accessing and creating objects within the server for use by applications.

to access the serverobjectadmin property, the application must be running as a user who is a member of the Administrators group. if the connected user is not a member of this group, attempts to access the serverobjectadmin property will fail. the serverobjectadmin property returns the iserverobjectadmin interface, which provides methods for administering the various aspects of the server, such as Server Object configurations and server machines. unless you are writing a GIS server administration application, your application does not need to make use of the iserverobjectadmin interface.

TheServerobjectmanagerObject provides methods for getting information about the GIS server and for creating server contexts for use by an application.

TheServerobjectadminObject provides methods for administrating the GIS server and its server objects.

when connecting to the server using the native. net connection object from a Web application or web service, you must also think about impersonation. your web application or Web Service must connect to the GIS server as a user in the agsusers group. the identity of the process or thread in determines the account you used to access the GIS server. process Identity is associated with the user account under which a process is running. for ASP. net web applications or web services you can impersonate a user at runtime by adding the identity tag to the Web. config File and defining the appropriate attributes.

<Identity impersonate = "true" username = "mydomain \ myuser" Password = "mypassword"/>

If you do not use impersonation in an ASP. NET application, then it will attempt to connect to the GIS server using the identity of the ASP. net worker process, which may be ASPnet or network service, depending on the platform and machine settings.

Thread level impersonation is provided via the Connection Library discussed earlier. an identity object is created with account credentials of a user in the agsusers group on the GIS server. when the agsserverconnection is instantiated, it is provided the identity object as a constructor parameter. the identity is used for the duration of the connection, which may involve concurrent access from multiple threads in the same process. the following code extends strates how a multi-threaded application creates concurrent connections to one or more GIS servers using different identities:

[C #]

Public partial class _ default: system. web. UI. page {private userthread m_thread; protected void button#click (Object sender, eventargs e) {m_thread = new userthread (); thread t = new thread (New threadstart (m_thread.connection1); T. start (); thread t2 = new thread (New threadstart (m_thread.connection2); t2.start () ;}} public class userthread {public void connection1 () {ESRI. arcGIS. ADF. identity Id = new ESRI. arcGIS. ADF. identity ("user1", "pass1", "domain1"); ESRI. arcGIS. ADF. connection. AGS. agsserverconnection agsconn; agsconn = new ESRI. arcGIS. ADF. connection. AGS. agsserverconnection ("server1", ID); agsconn. connect (); If (! Agsconn. isconnected) {agsconn. dispose (); return;} ESRI. arcGIS. server. iserverobjectmanager som = agsconn. serverobjectmanager; string servertype = "mapserver"; string serverobjectname = "Canada"; ESRI. arcGIS. server. iservercontext servercontext = som. createservercontext (serverobjectname, servertype); imapserver MS = (imapserver) servercontext. serverobject; system. threading. thread. sleep (10000); serve Rcontext. releasecontext (); agsconn. dispose ();} public void connection2 () {ESRI. arcGIS. ADF. identity id = new ESRI. arcGIS. ADF. identity ("user2", "pass2", "domain2"); ESRI. arcGIS. ADF. connection. AGS. agsserverconnection agsconn; agsconn = new ESRI. arcGIS. ADF. connection. AGS. agsserverconnection ("server2", ID); agsconn. connect (); If (! Agsconn. isconnected) {agsconn. dispose (); return;} ESRI. arcGIS. server. iserverobjectmanager som = agsconn. serverobjectmanager; string servertype = "mapserver"; string serverobjectname = "USA"; ESRI. arcGIS. server. iservercontext servercontext = som. createservercontext (serverobjectname, servertype); imapserver MS = (imapserver) servercontext. serverobject; servercontext. releasecontext (); agsconn. dispose ();}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.