我如何从浏览器调用此方法来了解服务的输出 [英] how can ia call this method from browser to know the output of the service

查看:116
本文介绍了我如何从浏览器调用此方法来了解服务的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

国际米兰



Inter

[ServiceContract]
public interface IService
{
    [OperationContract(Name = "EmployeeDetailsByEmpNoJson")]
    [WebInvoke(Method = "POST",
        ResponseFormat = WebMessageFormat.Json,
     UriTemplate = "EmployeeDetailsByEmpNoJson")]
    string EmployeeDetailsByEmpNoJson(string Schema, string Connection_Type, string Empno);

}





CLASS



CLASS

public class Service : IService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]

  public string EmployeeDetailsByEmpNoJson(string schema, string connect_Test_or_Production, string Empno)
  {

      try
      {


          if (fnOpenConnection(schema, connect_Test_or_Production) == true)
          {
              _objDataSet = new DataSet();
              _objOleDBCommand = new OleDbCommand();
              _objOleDBDataAdapter = new OleDbDataAdapter();

              _objOleDBCommand.Connection = _objOleDBConnection;
              _objOleDBCommand.CommandType = CommandType.Text;
              string strQuery = "select empname,desig,department,branch,to_char(doj,'dd-Mon-yyyy')doj,impact_lvl,comp_email,mob_co, project  from   vw_emp_dtls where  dol is null and empno=" + Empno + "";

              _objOleDBCommand.CommandText = strQuery;

              _objOleDBDataAdapter.SelectCommand = _objOleDBCommand;
              _objOleDBDataAdapter.Fill(_objDataSet);

              if (_objDataSet.Tables.Count > 0)
              {

                  System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                  List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
                  Dictionary<string, object> row;
                  foreach (DataRow dr in _objDataSet.Tables[0].Rows)
                  {
                      row = new Dictionary<string, object>();
                      foreach (DataColumn col in _objDataSet.Tables[0].Columns)
                      {
                          row.Add(col.ColumnName, dr[col]);
                      }
                      rows.Add(row);
                  }
                  return serializer.Serialize(rows);

             
              }
              else
              {
                  
                  return null;
              }
          }
          else
          {
             
              return null;
          }
      }
      catch (OleDbException dbEx)
      {
          return null;
      }
      catch (Exception ex)
      {
          return null;
      }
      finally
      {
          _objDataSet = null;
          _objOleDBCommand = null;
          _objOleDBDataAdapter = null;
          fnCloseConnection();
      }
  }



}


}

推荐答案

如果你想测试一下输出服务。使用fiddler并检查输出或添加一个testclient并检查输出。



如果你想使用Jquery调用服务。你可以使用这样的东西。如果要向服务器发布内容,可以将类型更改为POST。

If you want to just test the output of a service .Use fiddler and check the output or add a testclient and check the output.

If you want to call the service using Jquery. You could use something like this. You could change the type to "POST" if you are posting something to the server.
function CallService() {

var ajaxRequest =


.ajax({
type:GET,
url:http:// localhost:36161 / Service1.svc / EmployeeDetailsByEmpNoJson,
contentType:false,
processData:false
});


ajaxRequest.done(function(xhr,textStatus){
alert(textStatus);
});

ajaxRequest.fail(function(xhr,textStatus){
alert(textStatus);
});
}
.ajax({ type: "GET", url: "http://localhost:36161/Service1.svc/EmployeeDetailsByEmpNoJson", contentType: false, processData: false }); ajaxRequest.done(function (xhr, textStatus) { alert(textStatus); }); ajaxRequest.fail(function (xhr, textStatus) { alert(textStatus); }); }


这篇关于我如何从浏览器调用此方法来了解服务的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆