这段时间在写WCF,遇到一个很奇怪的问题,将WCF发布到IIS上后 IGISServerConnection.connet时总是不能连接。具体错误如下:
在 DCIPLServiceClient.ff()
很奇怪 ,用vs直接运行时能连接上的,不会报错。期间各种网上说的方法都试过,还是不成功。后来改用ADF来连接,不再报错。
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).
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 ServerObjectManagerand ServerObjectAdmin objects. The identity of the connecting user is not explicitly defined. Instead, the identity of the application is used.
The GISServerConnectionClass is a .NET generated wrapper for the GISServerConnection COM object.
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.
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;
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
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, then Connect will return an error.
In addition to the Connect method, the IGISServerConnection interface has two properties: ServerObjectManager and ServerObjectAdmin. If the application is running as a user in the users or administrators group, the application can access the ServerObjectManager property, which returns an IServerObjectManager interface. The IServerObjectManager interface 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.
The ServerObjectManager object provides methods for getting information about the GIS server and for creating server contexts for use by an application.
The ServerObjectAdmin object 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.
public partial class _Default : System.Web.UI.Page { private UserThread m_thread; protected void Button1_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); servercontext.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(); } }