控制短信猫收发短信 (调用WebServices)

需求说明:

  要求定时查询Doing表(待发短信)和短信猫中是否有数据,如果有信息则发送/接收。

表结构

  Doing(ID MOBILID CONTEXT USERNAME DOTIME) --待发送的短信
  Done(ID MOBILID CONTEXT SENDTIME USERNAME )--已发送的短信
  Receive(ID MOBILID CONTEXT RECEIVETIME)--接受道的短信

  GSMMultiPort.dll--控制猫的封装包(为提供)
  里面有:
 ‘初始化’,
 ‘获取短信猫标识号码’,
 ‘获取设备的连接状态’,
 ‘断开连接并释放内存空间’,
 ‘取得错误信息’,
 ‘发送短信息’,
 ‘接收短信息’等方法。

Service.cs代码
<----------------------------------------------------------------------------------------------->
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlTypes;
using System.Collections;

[WebService(Namespace = "此处为自己设定的XML命名空间")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]


public class Service : System.Web.Services.WebService
{
    public string myConnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("lmtof.mdb");
    protected OleDbConnection myconn;
    protected OleDbCommand mycommand;
    protected OleDbDataAdapter myda;
    protected OleDbTransaction mytran;
    protected DataSet ds;

    public Service ()
    {
        myconn = new OleDbConnection(myConnstring);
        //如果使用设计的组件,请取消注释以下行
        //InitializeComponent();    
    }

    #region //发信息
    [WebMethod/*是否有数据要发送*/]
    public string checkSMS()
    {
        string selectsql = "SELECT * FROM doing";
        mycommand = new OleDbCommand(selectsql, myconn);
        try
        {
            myconn.Open();
            if (Convert.ToInt32(mycommand.ExecuteScalar()) > 0)
            {
                return "true";
            }
            else
            { return "false"; }
        }
        catch (Exception ee)
        {
            return "ErrorWebService:"+ee.ToString();
        }
        finally { myconn.Close(); }
    }

    [WebMethod]
    public DataSet getSMS(out string error)
    {
        error = "";
        DataSet info=new DataSet();
        string selectsql = "SELECT CStr(id) + '|' + mobilid + '|'+context+'|'+username+'|'+cstr(dotime) FROM doing";
        try
        {
            myda = new OleDbDataAdapter(selectsql, myconn);
            myda.Fill(info);
            return info;
        }
        catch (Exception ee)
        {
            error = "ErrorWebService:" + ee.ToString();
            return info;         
        }

    }

    [WebMethod]
    //winform发送信息后,删除信息
    //错误编码为‘ErrorWebService:’+ 错误信息
    public string sendSMS(string uid ,string id , string mobilid, string context, string sendtime , string username )
    {
        if (uid != "oa.ftwsjd.gov.cn")
        {
            return "access denied";
        }
        try
        {
            //事务处理
            //myconn.Open();
            //mycommand = myconn.CreateCommand();
            //mytran = myconn.BeginTransaction();
            //mycommand.Transaction = mytran;
            //mycommand.CommandText = "INSERT INTO done(mobilid,context,username,sendtime) VALUES ('" + mobilid + "','" + context + "','" + username + "','" + sendtime + "')";
            //mycommand.ExecuteNonQuery();
            //mycommand.CommandText = "DELETE FROM doing WHERE id=" + id;
            //mycommand.ExecuteNonQuery();
            //mytran.Commit();
            return "true";
        }
        catch (Exception ee)
        {
            return "ErrorWebService:" + ee.ToString();
        }
        finally
        {
            myconn.Close();
        }
    }
    #endregion


    #region//收信息
    [WebMethod]
    //接收 SMS 插入Receive表中
    //错误编码为‘ErrorWebService:’+ 错误信息
    public string ReceiveSMS(string MOBILID, string CONTEXT, DateTime RECEIVETIME)
    {
        try
        {
            myconn.Open();
            mycommand = myconn.CreateCommand();          
            mytran = myconn.BeginTransaction();
            mycommand.Transaction = mytran;
            mycommand.CommandText = "INSERT INTO receive(MOBILID,CONTEXT,RECEIVETIME) VALUES ('" + MOBILID + "','" + CONTEXT + "','" + RECEIVETIME + "')";
            mycommand.ExecuteNonQuery();
            mytran.Commit();
            return "true";
        }
        catch (Exception ee)
        {
            return "ErrorWebService:" + ee.ToString();
        }
        finally
        { myconn.Close(); }
    }
    #endregion
}
<----------------------------------------------------------------------------------------------->

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值