简体   繁体   English

使用操作将表单参数发送到 Web 服务

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

Client-Side I'm trying to capture the fields like this:客户端我正在尝试捕获这样的字段:

// 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"
});

Now here's the problem I'm running into.现在这是我遇到的问题。 How do I send these parameters and set them in the web service using C# or vb.net if it's easier?如何使用 C# 或 vb.net 发送这些参数并在 web 服务中设置它们? Any help is greatly appreciated任何帮助是极大的赞赏

Here is what I have so far:这是我到目前为止所拥有的:

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 is an operation within the web service. SetProfile 是 web 服务中的操作。 SetProfileRequest is the message in the operation. SetProfileRequest 是操作中的消息。 I want to set certain parameters and then list other parameters in the code-behind file such as:我想设置某些参数,然后在代码隐藏文件中列出其他参数,例如:

access_time = 30;

I'm completely lost...help!我完全迷路了......救命!

Front-End Coder Lost in C# Translation前端编码器在 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 }; 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 };

So you need something like this:所以你需要这样的东西:

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

You will need a class in .NET like the following to match with your javascript object:您将需要 .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;
}

So the objects match and the names match.所以对象匹配并且名称匹配。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM