簡體   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#

我有以下用於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服務參考,則可以使用“代理”或“客戶端”,如下所示:

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

這將執行SOAP調用(或使用任何綁定)。

暫無
暫無

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

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