我已经设置了一个 Web 服务,但不知道如何在 MVC 5 c# 中从中获取数据

I have set up a web service but have no idea how to get data from it in MVC 5 c#

我有以下 Web 服务命名空间,我可以看到很多我可以访问的功能...

using MyService.api;

public class HomeController : Controller
{
    public ActionResult Index()
    {
        //What needs to go here?

        // LoginRequest and Response are types from the web service reference

        LoginRequest loginRequest = new LoginRequest();
        loginRequest.user = "blah";
        loginRequest.password = "abc1234";

        LoginResponse loginResponse = new LoginResponse();
        string sessionID = loginResponseSession.session.sessionId; // This has nothing in it

        return View("Index", sessionID );
    }
    ...

api 公开了所有这些方法,例如:

MachineRequest machineRequest = new MachineRequest();
string[] machines = machineRequest.machines;

当然,当我调用它时,它不会神奇地从 url 收集机器。

如何提出和回复请求?服务引用实际上是做什么用的?

你的问题有点不清楚。如果您生成了 WCF 服务引用,则可以像这样使用 "proxy" 或 "client":

var client = new MyService.api.ApiReferenceClient();
var loginResponse = client.LoginRequest(loginRequest);

这将执行 SOAP 调用(或正在使用的任何绑定)。