繁体   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