簡體   English   中英

使用參數c#調用webservice

[英]Calling webservice with parameters c#

我是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服務。 您創建代理類的對象並調用其各自的方法,這些方法在內部由框架轉換為SOAP調用。 只需右鍵單擊您的項目並使用“ 添加服務引用”而不是使用HttpWebRequest

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM