C#动态调用webServices(详细)

首先我们要创建好webServices项目文件可以是一个项目也可以是一个单独的文件放在其他项目中。

创建webServices文件的头部,引用依赖将AJAX调用此web服务取消注释。

/// <summary>
    /// AddApplyOnline 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://192.168.1.48:3030/AddApplyOnline.asmx/AddApplyOnlineData")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 
    [System.Web.Script.Services.ScriptService]

接下来是编写webServices方法如:

[SoapHeader("myheader")]
        [WebMethod]
        public string AddApplyOnlineData(string info)
        {
            bool result = false;
            string resultStr = "";
            try
            {
                //myheader.UserId= HttpContext.Current.Request.Form.Get("UserName");
                //myheader.UserPW = HttpContext.Current.Request.Form.Get("PWD");
                string msg = "";
                if (!myheader.IsValid(out msg))
                {
                    var resultJson = new
                    {
                        cod = -1,
                        resultText = msg,
                    };
                    resultStr = JsonConvert.SerializeObject(resultJson);
                }
                else
                {
                    Dmc_ApplicationRecord info1 = new Dmc_ApplicationRecord();
                    info1 = JsonConvert.DeserializeObject<Dmc_ApplicationRecord>(info);
                    #region 表单提交方法
                    //string txtCustomerName = HttpContext.Current.Request.Form.Get("txtCustomerName");
                    //string txtCompanyAddress = HttpContext.Current.Request.Form.Get("txtCompanyAddress");
                    //string txtName = HttpContext.Current.Request.Form.Get("txtName");
                    //string txtPhone = HttpContext.Current.Request.Form.Get("txtPhone");
                    //string txtWechat = HttpContext.Current.Request.Form.Get("txtWechat");
                    //string txtRamark = HttpContext.Current.Request.Form.Get("txtRamark");
                    //string txtField = HttpContext.Current.Request.Form.Get("txtField");
                    //info1.CustomerName = txtCustomerName;
                    //info1.Address = txtCompanyAddress;
                    //info1.ContactPhone = txtPhone;
                    //info1.ContactName = txtName;
                    //info1.WeChat = txtWechat;
                    //info1.ScopeName = txtField;
                    //info1.Remark = txtRamark;
                    #endregion
                    info1.CreateTime = DateTime.Now;
                    if (string.IsNullOrEmpty(info1.CustomerName) || string.IsNullOrEmpty(info1.ContactName) || string.IsNullOrEmpty(info1.ContactPhone) || string.IsNullOrEmpty(info1.Remark))
                    {
                        var resultJson = new
                        {
                            cod = -1,
                            resultText = "申请失败!必填数据不能为空!",
                        };
                        resultStr = JsonConvert.SerializeObject(resultJson);
                    }
                    else
                    {
                        info1.CreateTime = DateTime.Now;
                        result = _bLL.AddDmc_ApplicationRecord(info1);
                        if (result)
                        {
                            var resultJson = new
                            {
                                cod = 1,
                                resultText = "申请成功!",
                            };
                            resultStr = JsonConvert.SerializeObject(resultJson);
                        }
                        else
                        {
                            var resultJs
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值