得到IServerContext的两种方法
1、得到当前服务的IServerContext
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
UIComponent form = facesContext.getViewRoot().findComponent(
(String) paramMap.get("formId"));
if (form == null) {
return;
}
MapControl mapControl = (MapControl) form
.findComponent((String) paramMap.get("mapId"));
if (mapControl == null) {
return;
}
WebMap webMap = mapControl.getWebMap();
WebContext webContext = webMap.getWebContext();
// 得到当前服务的IServerContext
AGSLocalMapResource mapResource = (AGSLocalMapResource) webContext
.getResources().get("ags1");
MapServer mapServer = mapResource.getLocalMapServer();
IServerContext serverContext = mapResource.getServerContext();
2、通过服务器名链接
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
ServerConnection connection = null;
IServerObjectConfiguration serverObjectConfiguration = null;
try {
// 链接到服务器
ServerInitializer serverInitializer = new ServerInitializer();
serverInitializer.initializeServer("10.2.9.22",
"administrator", "oil");
connection = new ServerConnection();
connection.connect("10.2.9.22"); // 服务器名
// 链接到SOA
IServerObjectAdmin serverObjectAdmin = connection
.getServerObjectAdmin();
serverObjectConfiguration = serverObjectAdmin
.createConfiguration();
// 设置服务名称和类型
serverObjectConfiguration.setName("NewService");
serverObjectConfiguration.setTypeName("MapServer");
// 设置服务的属性信息
IPropertySet propertySet = serverObjectConfiguration
.getProperties();
propertySet.setProperty("FilePath", "D:\\test\\google.mxd");
serverObjectConfiguration.setIsPooled(true);
serverObjectConfiguration.setMaxInstances(1);
serverObjectConfiguration.setMinInstances(1);
serverObjectConfiguration.setWaitTimeout(10);
serverObjectConfiguration.setUsageTimeout(120);
// 将服务加到SOC中去
serverObjectAdmin.addConfiguration(serverObjectConfiguration);
}
catch (Exception e) {
e.printStackTrace();
} finally {
facesContext.responseComplete();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
UIComponent form = facesContext.getViewRoot().findComponent(
(String) paramMap.get("formId"));
if (form == null) {
return;
}
MapControl mapControl = (MapControl) form
.findComponent((String) paramMap.get("mapId"));
if (mapControl == null) {
return;
}
WebMap webMap = mapControl.getWebMap();
WebContext webContext = webMap.getWebContext();
// 得到当前服务的IServerContext
AGSLocalMapResource mapResource = (AGSLocalMapResource) webContext
.getResources().get("ags1");
MapServer mapServer = mapResource.getLocalMapServer();
IServerContext serverContext = mapResource.getServerContext();
2、通过服务器名链接
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
ServerConnection connection = null;
IServerObjectConfiguration serverObjectConfiguration = null;
try {
// 链接到服务器
ServerInitializer serverInitializer = new ServerInitializer();
serverInitializer.initializeServer("10.2.9.22",
"administrator", "oil");
connection = new ServerConnection();
connection.connect("10.2.9.22"); // 服务器名
// 链接到SOA
IServerObjectAdmin serverObjectAdmin = connection
.getServerObjectAdmin();
serverObjectConfiguration = serverObjectAdmin
.createConfiguration();
// 设置服务名称和类型
serverObjectConfiguration.setName("NewService");
serverObjectConfiguration.setTypeName("MapServer");
// 设置服务的属性信息
IPropertySet propertySet = serverObjectConfiguration
.getProperties();
propertySet.setProperty("FilePath", "D:\\test\\google.mxd");
serverObjectConfiguration.setIsPooled(true);
serverObjectConfiguration.setMaxInstances(1);
serverObjectConfiguration.setMinInstances(1);
serverObjectConfiguration.setWaitTimeout(10);
serverObjectConfiguration.setUsageTimeout(120);
// 将服务加到SOC中去
serverObjectAdmin.addConfiguration(serverObjectConfiguration);
}
catch (Exception e) {
e.printStackTrace();
} finally {
facesContext.responseComplete();
}