If anyone else is interested, the link above doesn't work, but you can download the javascript api proxy page here: http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jshelp_start.htm#jshelp/...I converted this over to vb.net since that is what I'm working in, minus the proxy.config file since I'm not working with tokens for my learning application. I also restricted the proxy to working with a single uri. I don't know if that is the best way to handle it, but in my readings it sounded like a good idea to limit what the page can be used for. I used a generic handler and here is the code for the ProcessRequest Sub. In your map xaml as Ali has done you can add a proxy tag, but just set it to "http://localhost:*current port number*/generichandler.ashx"Your *current port number* may change. Or if you have a server you can host your handler there and change the url accordingly.
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim response As HttpResponse = context.Response
Dim uri As String = HttpUtility.UrlDecode(context.Request.Url.Query.Substring(1))
If Not uri.Contains(urlStr) Then
response.StatusCode = 500
response.StatusDescription = "Wrong url detected"
response.Write("This proxy page is dedicated to a single url.")
response.End()
Return
End If
Dim req As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create(uri), System.Net.HttpWebRequest)
req.Method = context.Request.HttpMethod
req.ServicePoint.Expect100Continue = False
If context.Request.InputStream.Length > 0 Then
Dim bytes(context.Request.InputStream.Length) As Byte
context.Request.InputStream.Read(bytes, 0, context.Request.InputStream.Length)
req.ContentLength = bytes.Length
Dim contType As String = context.Request.ContentType
If String.IsNullOrEmpty(contType) Then
req.ContentType = "application/x-ww-form-urlencoded"
Else
req.ContentType = contType
End If
Using outputStream As Stream = req.GetRequestStream()
outputStream.Write(bytes, 0, bytes.Length)
End Using
End If
Dim serverResponse As System.Net.WebResponse = Nothing
Try
serverResponse = req.GetResponse()
Catch webExc As System.Net.WebException
response.StatusCode = 500
response.StatusDescription = webExc.Status.ToString()
response.Write(webExc.Response.ToString())
response.End()
Return
End Try
If Not serverResponse Is Nothing Then
response.ContentType = serverResponse.ContentType
Using byteStream As Stream = serverResponse.GetResponseStream()
If serverResponse.ContentType.Contains("text") Or serverResponse.ContentType.Contains("json") Then
Using sr As StreamReader = New StreamReader(byteStream)
Dim strResponse As String = sr.ReadToEnd
response.Write(strResponse)
End Using
Else
Dim br As New BinaryReader(byteStream)
Dim outb() As Byte = br.ReadBytes(serverResponse.ContentLength)
br.Close()
response.CacheControl = "no-cache"
response.OutputStream.Write(outb, 0, outb.Length)
End If
serverResponse.Close()
End Using
End If
response.End()
End Sub
Please let me know of any suggestions for improvement. Cheers,David