简体   繁体   中英

Calling webservice with parameters c#

I am new to webservices. I'm trying to call one this way just to see the result:

private void Form1_Load(object sender, EventArgs e)
{
    MessageBox.Show(getServiceResult("http://prod.sivaonline.pt/SAG.WS.SIVA.SVOLB2C/ViaturasNovas.asmx?wsdl"));
}

public string getServiceResult(string serviceUrl)
{
    HttpWebRequest HttpWReq;
    HttpWebResponse HttpWResp;
    HttpWReq = (HttpWebRequest)WebRequest.Create(serviceUrl);
    HttpWReq.Method = "GetMarcas";
    HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
    if (HttpWResp.StatusCode == HttpStatusCode.OK)
    {
    //Consume webservice with basic XML reading, assumes it returns (one) string
    XmlReader reader = XmlReader.Create(HttpWResp.GetResponseStream());
    while (reader.Read())
    {
        reader.MoveToFirstAttribute();
        if (reader.NodeType == XmlNodeType.Text)
        {
        return reader.Value;
        }
    }
    return String.Empty;
    }
    else
    {
    throw new Exception("Error on remote IP to Country service: " + HttpWResp.StatusCode.ToString());
    }
}

Now, it doesn't give me any message box. Is this normal? I want to add some parameters, like:

configurador=true

Visual Studio makes it easy to call web services by creating proxy classes for them on the client side. You create an object of the proxy class and calls its respective methods, which are internally converted into SOAP calls by the framework. Simply right-click on your project and use Add Service Reference instead of using HttpWebRequest .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM