Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm having troubles consuming a webservice.
The WS that I must consume works in two fases, first I must consume a simpler one, this I manage with this code:

public String ConectaWebService(String user, String pass, String tipo, String ip)
{
    var HtmlResult = "";
    var token = "";

    var URL = "myWebService";
    var myParameters = "login=" + user + "&password=" + pass + "&tipo=" + tipo;

    try
    {
        var wc = new WebClient();
        wc.Headers["Content-type"] = "application/x-www-form-urlencoded";
        HtmlResult = wc.UploadString(URL, myParameters);

        var start = HtmlResult.IndexOf("<auth-token>") + 12;
        var end = HtmlResult.IndexOf("</auth-token>", start);

        token = HtmlResult.Substring(start, end - start);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }

    return token;
}


This will return a XML with a token inside, this is ok too.

But after that I must consume another webservice, where I realy create the information that I want but I really didn't manage, I try several ways but nothing.

I try with HttpWebRequest, WebRequest and WebClient but without sucess.
It just didn't answer and says that the limet time is finish.

The things that I know is that is POST and the Content-type is application/x-www-form-urlencoded. I must send some parameters too, but not through the URL, It must be encoded with UTF8 and sent.

Please, can anyone help me?

Thanks a lot.

Raimundo
Posted
Comments
Kuthuparakkal 2-Mar-15 16:15pm    
Create a WebService Proxy, https://msdn.microsoft.com/en-us/library/bbs97dkt%28v=vs.90%29.aspx
[no name] 3-Mar-15 2:40am    
http://www.codeproject.com/Articles/2761/Consuming-Web-Services-from-a-Win-Forms-Applicatio

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