简体   繁体   English

我已经设置了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#

I have the following namespace for the web service and I can see lots of functions I can access... 我有以下用于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 );
    }
    ...

the api exposes all of these methods, things like: api公开了所有这些方法,例如:

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

But ofcourse when I call that, it does not magically go and collect machines from the url. 但是,当然,当我这样称呼它时,它并不能神奇地从URL中收集机器。

How do I make and respond to the requests? 如何提出并回应要求? What is the Service reference actually for? 服务参考实际上是什么?

Your question is a bit unclear. 您的问题还不清楚。 If you've generated a WCF service reference, you can use the "proxy" or "client" like this: 如果已生成WCF服务参考,则可以使用“代理”或“客户端”,如下所示:

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

That will perform the SOAP call (or whatever binding is being used). 这将执行SOAP调用(或使用任何绑定)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#如何从Asmx Web服务获取/设置数据 - C# How to get/set data from asmx Web Service 试图从C#将数据插入到Access数据库中,但是失败了,我也不知道为什么 - Trying to insert data into an access database from C#, but it fails, and I have no idea why 如何在C#MVC Web应用程序中发生定期事件? - How to have periodical events in a C# MVC web app? 如何使用带有属性 get 和 set 的 json 数据使用 C# 程序,并且我必须以表格格式显示数据? - how to use C# program using json data with the properties get and set and i have to display the data in a table format? 如何从C#MVC中的记录获取数据 - How do i get data from records in C# MVC 如何将XML Web Service中的返回纯文本添加到C#,MVC中的数据表中 - How to add return plain text from xml web service into data table in c#, mvc C#Web服务从SQL Server获取数据 - C# web service get data from sql server 如何从C#执行DOS SET命令并在exe关闭后保持变量? - How do I execute a DOS SET command from C# and have the variable persist after the exe closes? 如何在 c# 中从 System.Mvc.Web.ActionExecutingContext 获取请求正文数据 - How to get request body data from System.Mvc.Web.ActionExecutingContext in c# HttpWebRequest到C#中的Web服务; 如何从响应流中获取数据FAST? - HttpWebRequest to web-service in c#; how to get data FAST from the response stream?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM