简体   繁体   中英

.NET - Access webservice (.asmx) method using WebRequest in c#?

I got a .net project from client. Right now, I need to make a WebRequest to a WebService (.asmx). The problem is i dont know how call the method in that web service using web request from c#.

my code :

RunRoutines.aspx

string UseAddress = "http://localhost:31952/api/RunRoutines.asmx";
                string address = string.Format(UseAddress);
                HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(address); 

RunRoutines.asmx

public class RunRoutines : System.Web.Services.WebService
{

[WebMethod]
public string RunRR1()
{
    return "Hello World";
}
}

I need to access the RunRR1() method from the web request in RunRoutines.aspx. Please advise. Thanks!

Well you can access it using the name of the reference you have given while adding service reference.

For example if it is localHost then you can try below code:

var yourService = new localHost.WebService();

yourService.RunRR1();

For more details have a look here:

在此处输入图片说明

Image ref: http://www.c-sharpcorner.com/UploadFile/0c1bb2/consuming-web-service-in-Asp-Net-web-application/

Which is here for more details .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM