Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have used the following code to get authenticated and i successfully achieved it now using this authentication i have to futher proceed to get response from the url"http://localhost:8080/geonetwork/srv/en/xml.metadata.get"
this is the code i have used to get authentication
C#
protected void Page_Load(object sender, EventArgs e) 
    { 
        string RequestXML = "<request>" + 
                            "<username>admin</username>" + 
                            "<password>admin</password></request>"; 
        string ServerURL = "http://localhost:8080/geonetwork/srv/en/xml.user.login"; 
        string ResponseXML = postRequest(RequestXML, ServerURL); 
        Label1.Text = ResponseXML; 
    } 
 
    private string postRequest(String RequestXML, string ServerURL) 
    { 
        int timeout = 90000; 
        int connectionLimit = 10; 
        string responseXML = string.Empty; 
        try 
        { 
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(ServerURL); 
            webRequest.Timeout = timeout; 
            webRequest.KeepAlive = true; 
            webRequest.ServicePoint.ConnectionLimit = connectionLimit; 
            webRequest.Method = "POST"; 
            webRequest.ContentType = "text/xml"; 
            byte[] byteArray = Encoding.UTF8.GetBytes(RequestXML); 
            Stream strm = webRequest.GetRequestStream(); 
            strm.Write(byteArray, 0, byteArray.Length); 
            strm.Close(); 
            HttpWebResponse webResponse =(HttpWebResponse)webRequest.GetResponse(); 
            Encoding enc = Encoding.GetEncoding("utf-8"); 
            StreamReader reader = new StreamReader(webResponse.GetResponseStream(),enc); 
            responseXML = reader.ReadToEnd(); 
            reader.Close(); 
            webResponse.Close(); 
        } 
        catch (Exception ex) 
        { 
            throw (ex); 
        } 
        return responseXML; 
    }


using the above code i have to get the response from this url "http://localhost:8080/geonetwork/srv/en/xml.metadata.get" without losing the authentication pl help me in doing this
.
Posted
Updated 14-Nov-11 3:38am
v2
Comments
RaisKazi 14-Nov-11 9:43am    
That is a REST Call, which is stateless. What result you get when you call below url by your code?
"http://localhost:8080/geonetwork/srv/en/xml.metadata.get"
Shashwath7 14-Nov-11 11:26am    
hello RaisKazi

i get the 403 forbidden exception when i use this url(http://localhost:8080/geonetwork/srv/en/xml.metadata.get)
RaisKazi 14-Nov-11 12:50pm    
If it is your service then I can suggest below things.
1) Check you have configured Virtual Directory Propery.
2) Check you have written your Web/Get Method Properly.
3) If you are using Visual Studio then you may refer my below Tip/Trick Article to debug your REST Service.
http://www.codeproject.com/Tips/213007/Debug-WCF-REST-Service

1 solution

As RaisKazi[^] already wrote in a comment to your question, HTTP is per se stateless. Any state you would want would have to be implemented by your server application. A client could pass along a cooky or something that was passed back to it in a previous response to identify themselves to the server. For authentication purposes I'd advise you to use NetworkCredentials and have the service listen to requests over HTTPS.

Cheers!

—MRB
 
Share this answer
 
Comments
RaisKazi 14-Nov-11 10:32am    
Agree. Their should be some kind of authentication token maintained between two calls, which is indeed possible by implementing some logic in both Client and Service Application. 5ed!
Shashwath7 14-Nov-11 11:30am    
is there any logic which will be helpful in maintaining the authentication i achieved in the above code as well as to get the response from this url(http://localhost:8080/geonetwork/srv/en/xml.metadata.get)
RaisKazi 14-Nov-11 12:36pm    
It is possible if both Client and Service applications are in your development scope.

One trick which I used in past for this was using GuId, Generate new GuId when your authentication request gets passed. Save this GuId in the Database and return it as a response. Your seond request should send that GuId so that Service will verify it and will send response back if it is correct. Have a look at below link for GuId.
http://msdn.microsoft.com/en-us/library/system.guid.newguid.aspx
Sergey Alexandrovich Kryukov 14-Nov-11 12:40pm    
Agree, my 5.
--SA
thatraja 14-Nov-11 13:33pm    
5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900