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. FZU Problem 2168 防守阵地 I

    http://acm.fzu.edu.cn/problem.php?pid=2168 题目大意: 给定n个数和m,要求从n个数中选择连续的m个,使得a[i]*1+a[i+1]*2+--a[i+m]*m ...

  2. (转) 设置sqlplus中的退格键

    转自:http://blog.itpub.net/26110315/viewspace-717249/ 有些时候当你使用sqlplus登录到数据库中的时候,敲错了命令想要删除修改的时候,发现以前敲入的 ...

  3. NSString常见用法

    1.创建常量字符串 NSString *str = @"Hello World!"; 2.创建空字符串,给予赋值 NSString *str = [[NSString alloc] ...

  4. MAVEN Error: Using platform encoding (GBK actually) to copy filtered resources.....

    环境:Maven3.2.5+MyEclipse 2015CI 现象:在Maven编译过程中出现错误信息:Using platform encoding (GBK actually) to copy f ...

  5. IE9下不显示select

    由于IE8和IE9下不兼容,需要在头部加入: <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7&q ...

  6. ldap chinese guide

    OpenLDAP2.4管理员指南 http://wiki.jabbercn.org/index.php/OpenLDAP2.4%E7%AE%A1%E7%90%86%E5%91%98%E6%8C%87% ...

  7. Spring的事务管理和数据库事务相关知识

    1 初步理解 理解事务之前,先讲一个你日常生活中最常干的事:取钱.         比如你去ATM机取1000块钱,大体有两个步骤:首先输入密码金额,银行卡扣掉1000元钱:然后ATM出1000元钱. ...

  8. WEB应用图片的格式,以及各自的特点和优化(一) by FungLeo

    WEB应用图片的格式,以及各自的特点和优化(一) by FungLeo 前言 12年前我入行三天.用table布局做了一个非常粗糙的网页.我说了一句话,"网页就是表格加文字加图片,图片分两种 ...

  9. html5+js压缩图片上传

    最近在折腾移动站的开发,涉及到了一个手机里面上传图片.于是经过N久的折腾,找到一个插件,用法如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...

  10. com.octo.captcha.service.CaptchaServiceException: Invalid ID, could not validate unexisting o

    <p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px;"& ...