簡體   English   中英

使用操作將表單參數發送到 Web 服務

[英]Sending Form Parameters to Web-service using Operations

客戶端我正在嘗試捕獲這樣的字段:

// Initialize the object, before adding data to it.
//  { } is declarative shorthand for new Object().
var NewSubscriber = { };

NewSubscriber.FirstName = $("#FirstName").val();
NewSubscriber.LastName = $("#LastName").val();
NewSubscriber.Email = $("#Email").val();
NewSubscriber.subscriptionID = $("#subscriptionID").val();
NewSubscriberNewPerson.Password = "NewPassword1";
NewSubscriber.brokerID = "239432904812";

// Create a data transfer object (DTO) with the proper structure.
var DTO = { 'NewSubscriber' : NewSubscriber };

$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "NewSubscriberService.asmx/AddDigitalSubscriber",
data: JSON.stringify(DTO),
dataType: "json"
});

現在這是我遇到的問題。 如何使用 C# 或 vb.net 發送這些參數並在 web 服務中設置它們? 任何幫助是極大的贊賞

這是我到目前為止所擁有的:

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



    public SubNameSpace.WebServiceSubBook.drmProfile _profile;


    [WebMethod]
    public string SetProfileData (object DTO) {
        SetProfile (DTO);


    }
    [WebMethod]
    public class SetProfileData (SubNameSpace.WebServiceSubBook.drmProfile _profile;) {
        this._profile = _profile;


        return "success";
    }
 }
}

SetProfile 是 web 服務中的操作。 SetProfileRequest 是操作中的消息。 我想設置某些參數,然后在代碼隱藏文件中列出其他參數,例如:

access_time = 30;

我完全迷路了......救命!

前端編碼器在 C# 翻譯中丟失

Your javascript object's first 'head' id NewSubscriber must match your web methods signature, for example: you are calling url: "NewSubscriberService.asmx/AddDigitalSubscriber", with var DTO = { 'NewSubscriber': NewSubscriber };

所以你需要這樣的東西:

[WebMethod]
public string AddDigitalSubscriber(NewSubscriber NewSubscriber)
{
    string status = string.Empty;
    // Add Subscriber...
    string emailFromJavascript = NewSubscriber.Email;
    // do something
    return status;
}

您將需要 .NET 中的 class 與您的 javascript object 相匹配:

//... Class in .NET
public class NewSubscriber
{
    public string FirstName;
    public string LastName;
    public string Email;
    public int subscriptionID;
    public string Password;
    public string brokerID;
}

所以對象匹配並且名稱匹配。

暫無
暫無

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

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