Arcgis Server发布的地图服务地址默认端口号是6080,假设本机上只对80端口做了外网映射,在IIS中部署了一个网站绑定了80端口,那么网站中某个页面通过arcgis api for js 加载Arcgis Server发布的地图服务就无法加载出来了。

在此情况下,可以将Arcgis Server发布的地图服务地址Url设为网站的特定地址,然后通过拦截器拦截特定地址,在拦截器中用HttpWebRequest访问localhost:6080,将HttpWebResponse响应流写入Response.OutputStream中。

(其实就是类似于反向代理,将地图服务接口的请求转发到Arcgis Server 的Web服务器)

例:

  服务器局域网地址为:192.168.1.100

  服务器80端口映射外网地址为:61.135.169.125

  服务器在IIS中部署网站绑定的端口为:80

  服务器Arcgis Server发布的地图服务地址端口为:6080

现在如果想通过arcgis js api 加载 服务接口 192.168.1.100:6080/arcgis/rest/services/test/service1/FeatureServer/0;

如果在内网中访问,下面的代码地图加载出来没问题。

var myFeatureLayer0 = new FeatureLayer("http://192.168.1.100:6080/arcgis/rest/services/test/service1/FeatureServer/0", { "id": "myFeatureLayer0", "opacity": 0.5, "outFields": ["*"], "mode": FeatureLayer.MODE_ONDEMAND });

但是如果在外网访问因为无法访问6080端口,所以必须通过80端口的网站通过模拟HttpWebRequest模拟请求 192.168.1.100:6080/arcgis/rest/services/test/service1/FeatureServer/0 ,然后返回客户端

html页面代码:

var myFeatureLayer0 = new FeatureLayer("http://61.135.169.125/arcgis/rest/services/test/service1/FeatureServer/0", { "id": "myFeatureLayer0", "opacity": 0.5, "outFields": ["*"], "mode": FeatureLayer.MODE_ONDEMAND });

HttpModule拦截器代码:

    public class ArcgsiServerUrlMappingModule : IHttpModule
{
public void Init(HttpApplication application)
{
application.BeginRequest += this.Application_BeginRequest; //注册事件
} private void Application_BeginRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
string url = application.Context.Request.RawUrl;
if (url.StartsWith("/arcgis/rest/services"))
{
url = "http://192.168.1.100:6080" + url;
HttpWebRequest hwRequest = (HttpWebRequest)WebRequest.Create(url);
hwRequest.UserAgent = "User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705";
hwRequest.Accept = "*/*";
hwRequest.KeepAlive = true;
hwRequest.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.5");
using (HttpWebResponse hwResponse = (HttpWebResponse)hwRequest.GetResponse())
{
Stream hwStream = hwResponse.GetResponseStream();
byte[] buffer = new byte[];
int count = ;
while ((count = hwStream.Read(buffer, , buffer.Length)) > )
{
application.Context.Response.OutputStream.Write(buffer, , count);
}
application.Context.Response.ContentType = hwResponse.ContentType;
application.Context.Response.End();
}
}
} public void Dispose() { }
}
HttpModule需要在Web.config中的<system.webServer>节点配置相关节点才能起到拦截请求的作用,在次不做说明。

附设计流程图

Arcgis api for javascript学习笔记 - 不改变默认端口(6080)情况下,外网访问Arcgis Server 发布的接口的更多相关文章

  1. Arcgis api for javascript学习笔记(4.5版本) - 获取FeatureLayer中的graphics集合

    在Arcgis api for javascript 3.x 版本中,我们可以直接通过某个FeatureLayer对象中的graphics属性获取要素集合. graphics属性 但是在4.x版本中, ...

  2. Arcgis api for javascript学习笔记(4.5版本) - 本地部署及代理配置

    在开发过程中,由于api的文件比较多,没必要每个项目都将api加入到解决方案中.况且在VS中如果将api加入解决方案,在编写css或js代码时,由于智能提示需要扫描脚本等文件,会导致VS很卡.所以个人 ...

  3. Arcgis api for javascript学习笔记(3.2X版本)-初步尝试

    Arcgis api for javascript(3.22版本)官方地址 :https://developers.arcgis.com/javascript/3/ 1. 根据官方示例实现一个简单地图 ...

  4. Arcgis api for javascript学习笔记(4.5版本) - 点击多边形(Polygon)并高亮显示

    在现在的 arcgis_js_v45_api 版本中并没有直接提供点击Polygon对象高亮显示.需要实现如下几个步骤: 1.点击地图时,获取Polygon的Graphic对象: 2.对获取到的Gra ...

  5. Arcgis api for javascript学习笔记(4.6版本) - 二维MapView中的FeatureLayer显示标注

    4.6版本api的FeatureLayer中有提供 labelsVisible 和 labelingInfo 两个属性,设置这两个属性可以实现显示将属性中某个字段作为标注.但是这两个属性只针对三维Sc ...

  6. Arcgis api for javascript学习笔记-控制地图缩放比例尺范围(3.2X版本与4.6版本)

    Ⅰ. 在3.X版本中,设置Map对象的 "maxScale" 和 "minScale" 属性 <!DOCTYPE html> <html> ...

  7. Arcgis api for javascript学习笔记(4.5版本)-三维地图实现弹窗功能

    1. 对于Graphic对象,在初始化Graphic对象时设置popupTemplate属性,即可实现点击Graphic时显示弹窗. <!DOCTYPE html> <html> ...

  8. Arcgis api for javascript学习笔记(4.5版本)-三维地图的飞行效果

    其实就只是用到了 view.goTo()  函数,再利用 window.setInterval()  函数(定时器)定时执行goTo().代码如下: <!DOCTYPE html> < ...

  9. Arcgis api for javascript学习笔记(4.5版本)-三维地图并叠加天地图标注

    1.三维地图实现 在官网的demo中就有三维地图的实现,如下图所示 <!DOCTYPE html> <html> <head> <meta charset=& ...

随机推荐

  1. UVA 11437 - Triangle Fun 向量几何

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. Linear to physical address translation with support for page attributes

    Embodiments of the invention are generally directed to systems, methods, and apparatuses for linear ...

  3. [TypeStyle] Reusable styles using TypeStyle mixins

    TypeStyle’s style function allows you to give multiple objects as an argument. This provides a simpl ...

  4. Apache+tomcat的整合 分类: C_OHTERS 2014-05-07 15:08 293人阅读 评论(0) 收藏

    http://blog.csdn.net/stefyue/article/details/6918542 为什么要做这个整合呢?当然,首先想到是就是Apache和Tomcat的区别.正因为有区别,有各 ...

  5. Android 使用binder访问service的方式

    binder机制是贯穿整个Android系统的进程间访问机制,经常被用来访问service,我们结合代码看一下binder在访问service的情形下是怎么具体使用的. service 你可以理解成没 ...

  6. java生成6位随机数

    生成6位随机数(不会是5位或者7位,仅只有6位): System.out.println((int)((Math.random()*9+1)*100000)); 同理,生成5位随机数: System. ...

  7. USB 3.0规范中译本 第8章 协议层

    本文为CoryXie原创译文,转载及有任何问题请联系cory.xie#gmail.com. 协议层管理设备及其主机之间端到端的数据流.这一层建立在链路层提供对某些类型的包的保证传输(guarantee ...

  8. 《转》couldn&#39;t connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145

    couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145,有须要的朋友能够參考下. 应为昨天安装的时候没及时 ...

  9. Thinking in UML 学习笔记(四)——UML核心视图之活动图

    在UML中活动图的本质就是流程图,它描述了为了完成某一个目标需要做的活动以及这些互动的执行顺序.UML中有两个层面的活动图,一种用于描述用例场景,另一种用于描述对象交互. 活动图只是我们用来描述业务目 ...

  10. sql for xml 还有一种写法(採用 tag 与 union all,简洁易懂)

    sql for xml 还有一种写法(採用 tag 与 union all,简洁易懂) 測试环境:sql 08, 08 R2, 2010,  2012, 2014 等 declare @agent t ...