客户端我正在尝试捕获像这样的字段:
// 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#翻译中丢失的前端编码器
最佳答案
您的javascript对象的第一个'head'ID NewSubscriber
必须与您的网络方法签名匹配,例如:
您正在使用url: "NewSubscriberService.asmx/AddDigitalSubscriber",
调用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中的如下类与您的javascript对象进行匹配:
//... Class in .NET
public class NewSubscriber
{
public string FirstName;
public string LastName;
public string Email;
public int subscriptionID;
public string Password;
public string brokerID;
}
因此,对象匹配且名称匹配。