Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Communicating with web application from windows application with out using web service

Posted on 2010-09-03
7
Medium Priority
?
458 Views
Last Modified: 2012-05-10
Hi,

I am working with a windows application where i need to pass login name and password to a web application and get result from that web application whether that passed login and password are valid or invalid.

I dont have any information on web services exposed that web application. SO i can not consume the web service.

But still i wnt to get the result. How can I handle this.

Please provide the answer ASAP.

Thanks,
Srinivas Mateti
0
Comment
Question by:futurebuilders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 11

Accepted Solution

by:
madgino earned 2000 total points
ID: 33602185
You can make a http request and read the response, it shouldn't be very complicated using .NET.
0
 

Author Comment

by:futurebuilders
ID: 33602192
If in that case can u plase provide some sample code.it will be helpful to my work.


Thanks in advance
Srinivas Mateti
0
 
LVL 11

Assisted Solution

by:madgino
madgino earned 2000 total points
ID: 33602910
So first you need to see how the website handles the POST and which fields are submitted (usually there are username & passowrd). For this you need to have a debugger/proxy to show you the POST data, I would recommend you fiddler (http://www.fiddler2.com/fiddler2/).
So install fiddler, go to the website and login. When you press the login button check in fiddler the POST variables that are used.

Then you create a similar post in your application with the same POST variables, you have here some examples:
http://www.netomatix.com/httppostdata.aspx
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:futurebuilders
ID: 33603241
thanks for your response.

So my client application is windows aplication.I am unable to use HTTPRequest class in windows application.

Your solution will work in web application or it will work in windows also?

Please clarify my doubt.

If it works for windows application also then how can i use httprequest class in windows application

Thanks
Srinivas Mateti
0
 
LVL 11

Assisted Solution

by:madgino
madgino earned 2000 total points
ID: 33603358
You can use HttpWebRequest from windows application, it's in System.Net.

You have attached the function that I'm using in my windows app. The difference is that I'm doing a simple GET you must do a POST like in the other examples.

public static string GetPage(string strURL)
        {
            try
            {

                //get main page
                byte retries = 0;
                retry:

                HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(strURL);

                wRequest.Proxy = WebRequest.GetSystemWebProxy();
                wRequest.Proxy.Credentials = CredentialCache.DefaultCredentials;
                wRequest.Credentials = CredentialCache.DefaultCredentials;
                wRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)";
                wRequest.CookieContainer = new CookieContainer();

                Uri swUri = new Uri(strURL);
                
                HttpWebResponse wResponse;
           
                try
                {
                    wResponse = (HttpWebResponse)wRequest.GetResponse();
                }
                catch (WebException ex)
                {
                    //let's log the error
                    retries++;
                    if (retries > 2) throw ex;
                    goto retry;
                }

                Encoding enc;
                if ((wResponse.ContentEncoding != null) && (wResponse.ContentEncoding.Length > 0))
                {
                    enc = Encoding.GetEncoding(wResponse.ContentEncoding);
                }
                else if ((wResponse.CharacterSet != null) && (wResponse.CharacterSet.Length > 0))
                {
                    enc = Encoding.GetEncoding(wResponse.CharacterSet);
                }
                else
                {
                    //enc = Encoding.GetEncoding(1252);  // Windows default Code Page
                    enc = Encoding.GetEncoding("utf-8");
                }

                StreamReader loResponseStream = new StreamReader(wResponse.GetResponseStream(), enc);

                string strHtml = loResponseStream.ReadToEnd();

                wResponse.Close();
                loResponseStream.Close();

                return strHtml;

            }
            catch (Exception ex)
            {
                Utilities.LogError("Error on " + strURL + " =>" + ex.Message.ToString(), ex.StackTrace.ToString(), false);
            }
            finally
            {
            }
            return "";

        }

Open in new window

0
 

Author Comment

by:futurebuilders
ID: 33604248
Hi,

Here again a issue. My taget url contains 2 web sites.

Please see my url "https://us.battle.net/login/en/login.xml?ref=https://www.worldofwarcraft.com/account/&app"

How to handle 2 urls in sigle httprequst class.

I hv to pass user name and password and get the validation result for the user.
Please give me some guidelines as i am new to this kind of environment.

Thanks,
Srinivas Mateti
0
 
LVL 11

Assisted Solution

by:madgino
madgino earned 2000 total points
ID: 33613057
Sorry for now I don't have the time to write the code for you but maybe this will work:
http://pastebin.com/QB4B1C3t

You actually have only one url, the other one is a parameter of the main url.
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question