Last post Apr 16, 2013 02:08 PM by psinet
Apr 13, 2013 04:46 PM|superqtip182|LINK
First of all, I apologize if this is not in the right subforum.
I have created a basic API that allows a user to click a link that creates an account on our client's website. Currently, the customer is logged in and brought to the customer's profile page if the creation is successful, otherwise the customer is brought
to an error page. Our client would like to change the customer creation method so that instead of the customer creating a link, our client simply makes calls to our server and receives a response in an XML document.
I have created a simple ASHX (CreateCustomer.ashx) page with the following code:
/// Summary description for $codebehindclassname$
public class CreateCustomer : IHttpHandler
public void ProcessRequest(HttpContext context)
context.Response.ContentType = "text/plain";
public bool IsReusable
For now, I simply want to see if I can even get the "Hello World" response.
In my ASPX page (https://www.mywebsite.com/APITestCaller.aspx), I make an HTTP Web Request to "https://www.mywebsite.com/CreateCustomer.ashx" using an HTTP Wrapper (a programmer who used to work at our company wrote this wrapper for something else):
public static HTTPResponse SendToHTTP(string URL, string Method, string Message, string ContentType)
HTTPResponse retval = new HTTPResponse();
byte Bytes = Encoding.ASCII.GetBytes(Message);
retval.RequestURL = URL + Message;
HttpWebRequest HTTP = (HttpWebRequest)WebRequest.Create(URL);
HTTP.Method = Method;
if (ContentType != "")
HTTP.ContentType = ContentType;
if (Method.ToUpper() == "POST")
HTTP.ContentLength = Bytes.Length;
Stream os = HTTP.GetRequestStream();
os.Write(Bytes, 0, Bytes.Length);
HttpWebResponse Resp = (HttpWebResponse)HTTP.GetResponse();
if (Resp == null)
retval.ResponseCode = -1;
retval.Body = "No response";
StreamReader sr = new StreamReader(Resp.GetResponseStream());
retval.ResponseCode = (int)Resp.StatusCode;
retval.ResponseMsg = Resp.StatusCode.ToString();
retval.Body = sr.ReadToEnd().Trim();
catch (Exception e)
retval.ResponseCode = -1;
retval.Body = e.Message;
The response message I get is "Unable to connect to the remote server" with a response code of "-1" (which is obviously due to request code). Keep in mind that ultimately my code for the request won't matter because our client will be in charge of the request,
but I included it in case that is what is causing the error message.
Is this an IIS issue? Or is my coding for the response bad? Anything else it could be?
Apr 13, 2013 05:18 PM|smirnov|LINK
To make a web request to a remote URL via HTTPS protocol, it’s required more works than via HTTP because it needs to validate the SSL Certificate. Here's
some hint. Hope it helps.
Apr 13, 2013 05:31 PM|superqtip182|LINK
I know that my request code works with HTTPS already because I've used it before on another URL that had HTTPS.
Apr 13, 2013 05:49 PM|smirnov|LINK
from the same domain/certificate where CreateCustomer.ashx is?
Apr 13, 2013 09:45 PM|thirumaran007|LINK
This should be problem with your certificate, is that certificates configured in your server properly ?
Apr 15, 2013 02:19 PM|superqtip182|LINK
I took a look at the example... should I be able to get a response just by accepting any certificate like the example shows? I am still getting the same response.
Apr 15, 2013 02:27 PM|superqtip182|LINK
Another question I have is, may I make a request directly to https://www.mywebsite.com/CreateCustomer.ashx or is the ashx just a handler for an aspx page?
Apr 16, 2013 01:04 PM|superqtip182|LINK
Apr 16, 2013 02:08 PM|psinet|LINK
To answer to the last question you posted, a HttpHandler can be called directly in the browser like
http://mysite/handler.ashx. You can think of a handler it like calling a regular aspx page except you control the output directly.
Here's some more info if you need it -
Custom ASP.NET procesing for HttpHandlers