In JavaScript I am adding a proxy rule as such....
urlUtils.addProxyRule({
urlPrefix: "https://xxxx.xxxx.xxxx.gov/arcgis/rest/services/Testing/Test/FeatureServer/0",
proxyUrl: "https://xxxx.xxxx.xxxx.gov/DotNet/proxy.ashx"
});
But I have a .Net app that I need to call a GP Service from C# BUT I want to run it through the proxy so Credentials are not needed....
How would I modify this code to work in C# so I can use it to bypass credentials on a secured GP Service
urlUtils.addProxyRule({
urlPrefix: "https://xxxx.xxxx.xxxx.gov/arcgis/rest/services/Testing/Test/GP_TOOL/",
proxyUrl: "https://xxxx.xxxx.xxxx.gov/DotNet/proxy.ashx"
});
Solved! Go to Solution.
I got it with this....I went another route and got a Token for the service....I will simply apply that to the Service when I call it to satisfy the Credentials needed.
// GET TOKEN
public String GetToken()
{
string result = null;
try
{
string gpUrl = "https://xxxx.xxxx.xxxx.gov/arcgis/tokens/generateToken?username=User&password=U$er&expiration=15&f=json";
string reqString = gpUrl;
HttpWebRequest req = WebRequest.Create(new Uri(reqString)) as HttpWebRequest;
req.Method = "POST";
req.ContentType = "application/json";
// Encode the parameters as form data:
byte[] formData = UTF8Encoding.UTF8.GetBytes(reqString);
//req.contentLength = formData.Length;
// Send the request:
using (Stream post = req.GetRequestStream())
{
post.Write(formData, 0, formData.Length);
}
// Pick up the response:
//string result = null;
using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
{
StreamReader reader =
new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
Console.WriteLine(result.ToString());
}
return result;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
result = ex.Message;
return result;
}
}
In my Web.config I have the URL referenced
<setting name="deletePoints_Dev" serializeAs="String">
<value>https://xxxx.xxxx.xxxx.gov/arcgis/rest/services/Testing/GPToolEditor/FeatureServer/0</value>
</setting>
When I go to use this GP Tool I do this
public Boolean DeleteAllPointsFromTable()
{
try
{
string whereClause = "OBJECTID>-1";
string gpUrl = deletePoints_Dev;
if (production) gpUrl = deletePoints_Prod;
string reqString = gpUrl + "/deleteFeatures?where=" + whereClause;
BUT I am going to lok down this GP Tool URL like a Feature Service. Where in this workflow would I add the Proxy to bypass this authentication?
WHERE do I put this Proxy Rule?
HOW do I write this in C#
urlUtils.addProxyRule({
urlPrefix: "https://xxxx.xxxx.xxxx.gov/arcgis/rest/services/Testing/GPToolEditor/FeatureServer/0",
proxyUrl: "https://xxxx.xxxx.xxxx.gov/DotNet/proxy.ashx"
});
Can I do something like this exmaple? BUT I NEED C#
I got it with this....I went another route and got a Token for the service....I will simply apply that to the Service when I call it to satisfy the Credentials needed.
// GET TOKEN
public String GetToken()
{
string result = null;
try
{
string gpUrl = "https://xxxx.xxxx.xxxx.gov/arcgis/tokens/generateToken?username=User&password=U$er&expiration=15&f=json";
string reqString = gpUrl;
HttpWebRequest req = WebRequest.Create(new Uri(reqString)) as HttpWebRequest;
req.Method = "POST";
req.ContentType = "application/json";
// Encode the parameters as form data:
byte[] formData = UTF8Encoding.UTF8.GetBytes(reqString);
//req.contentLength = formData.Length;
// Send the request:
using (Stream post = req.GetRequestStream())
{
post.Write(formData, 0, formData.Length);
}
// Pick up the response:
//string result = null;
using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
{
StreamReader reader =
new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
Console.WriteLine(result.ToString());
}
return result;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
result = ex.Message;
return result;
}
}