我是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
答案 0 :(得分:2)
Visual Studio通过在客户端为它们创建代理类,可以轻松调用Web服务。您创建代理类的对象并调用其各自的方法,这些方法在内部由框架转换为SOAP调用。只需右键单击您的项目并使用添加服务参考,而不是使用HttpWebRequest
。