Reputation: 55
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
Upvotes: 0
Views: 11352
Reputation: 35400
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
.
Upvotes: 2