如何将参数从jquery发送到WCF(在使用WCF中)?

时间:2013-01-30 06:41:28

标签: jquery json wcf html5

我正在使用Html5和jquery来消费wcf。在WCf我有sendmail,它包含两个参数作为注释和toaddress。我需要使用jquery / json / ajax从另一个应用程序传递的值。

![wcf中的sendmail方法] [1]

 public string SendMail(string strEmailAddrTo, string strcomments)
{
    string strSent = " ";
    try
    {
        myMailMessage = new MailMessage();
        myMailMessage.To.Add(new MailAddress(strEmailAddrTo));
        // Obtains the e-mail address of the person sending the message. 
        myMailMessage.From = new MailAddress("divya@gmail.com", "Divya");

        // Obtains the subject of the e-mail message 
        myMailMessage.Subject = "Welcome to ";

        // Obtains the body of the e-mail message. 
        myMailMessage.IsBodyHtml = true;
          myMailMessage.Body = "Thanks for your feedback as :     "+ strcomments;
        myMailMessage.Priority = MailPriority.High;

        SmtpClient myMailClient = new SmtpClient();

我写了html页面如下

![使用Html5消耗wcf,jquery / ajax] [2]  函数WCFJSON(){

    var strEmailAddrTo = document.getElementById("strEmailAddrTo");
    var strcomments = document.getElementById("strcomments");
     Type = "POST";
    Url = "http://localhost:2176/WCFService1/Service.svc/SendMail";
   Data = '{"strEmailAddrTo": "' + strEmailAddrTo.value + '","strcomments": "'+strcomments.value+'"}';
  //data: JSON.stringify(myObject),
    ContentType = "application/json; charset=utf-8";
  DataType = "json"; varProcessData = true;
  alert((strEmailAddrTo));
    CallService();
}
function CallService() {

    $.ajax({

        type: Type, //GET or POST or PUT or DELETE verb
        url: Url, // Location of the service
        data: Data, //Data sent to server
        contentType: ContentType, // content type sent to server
        dataType: DataType, //Expected data format from server
        processdata: ProcessData, //True or False
        success: function (msg) {//On Successfull service call
            ServiceSucceeded(msg);
        },
        error: ServiceFailed// When Service call fails
    });
}

但是我无法发布值,我也不确定传递的多个值是否正确。 请建议我如何通过这些2值。

先谢谢。

0 个答案:

没有答案