0

我是网络服务的新手。我试图以这种方式调用一个只是为了查看结果:

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
4

1 回答 1

2

Visual Studio 通过在客户端为它们创建代理类来轻松调用 Web 服务。您创建代理类的对象并调用其各自的方法,这些方法在框架内部转换为 SOAP 调用。只需右键单击您的项目并使用Add Service Reference而不是使用HttpWebRequest.

于 2013-05-02T09:51:04.547 回答