调用带有参数的webservice c#
本文关键字:webservice 参数 调用 | 更新日期: 2023-09-27 18:11:42
我是webservices的新手。我试着这样调用一个,只是为了看看结果:
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());
}
}
现在,它没有给我任何消息框。这正常吗?我想添加一些参数,比如:
configurador=true
Visual Studio通过在客户端为web服务创建代理类,使调用web服务变得容易。您创建代理类的对象并调用其各自的方法,这些方法由框架在内部转换为SOAP调用。只需右键单击您的项目并使用添加服务引用而不是使用HttpWebRequest
。