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"开发者_StackOverflow).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? 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. SetProfileRequest is the message in the operation. 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
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:
//... 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.
精彩评论