- C# code
public class PhoneMsg : System.Web.Services.WebService { [DllImport("sms.dll", EntryPoint = "Sms_Connection")] public static extern uint Sms_Connection(string CopyRight, uint Com_Port, uint Com_BaudRate, out string Mobile_Type, out string CopyRightToCOM); [DllImport("sms.dll", EntryPoint = "Sms_Disconnection")] public static extern uint Sms_Disconnection(); [DllImport("sms.dll", EntryPoint = "Sms_Send")] public static extern uint Sms_Send(string Sms_TelNum, string Sms_Text); public PhoneMsg() { } // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 // [System.Web.Script.Services.ScriptService] public class Service1 : System.Web.Services.WebService { [WebMethod] /*public string HelloWorld() { return "Hello World"; }*/ [SoapRpcMethod(Action = "http://www.wapasp.net/SendMessage", RequestNamespace = "http://www.wapasp.net/")] public string SendMessage(string sPhoneNum, string sContent) { String TypeStr = ""; String CopyRightToCOM = ""; String CopyRightStr = "//参考//"; try { if (Sms_Connection(CopyRightStr, 1, 9600, out TypeStr, out CopyRightToCOM) == 1) ///5为串口号,0为红外接口,1,2,3,...为串口 { string[] sPhoneArr = sPhoneNum.Split(','); for (int i = 0; i < sPhoneArr.Length; i++) { [color=#FF0000]Sms_Send(sPhoneArr, sContent);[/color] } //Sms_Send("13523661507", "aaaaaa"); Sms_Disconnection(); return "发送成功!"; } } catch (Exception ex) { return ex.ToString(); } return "发送失败!"; //return sPhoneNum + ":" + sContent; } } } }
学着用webservice编写一个短信收发的接口,做到发送这块时提示两个错误,出在红色标明的地方,第一个是与send方法具有一些无效参数,第二个是无法将string[]转换成string,希望各位大虾能帮我改改= =
------解决方案--------------------
第一个send参数不对,那就只有自己去核实与提供的接口是否匹配了
第二个,估计和第一个一样,还是接口没有匹配
------解决方案--------------------
if (Sms_Connection(CopyRightStr, 1, 9600, out TypeStr, out CopyRightToCOM) == 1) ///5为串口号,0为红外接口,1,2,3,...为串口
{
string[] sPhoneArr = sPhoneNum.Split(',');
for (int i = 0; i < sPhoneArr.Length; i++)
{
Sms_Send(sPhoneArr[i], sContent); }
//Sms_Send("13523661507", "aaaaaa");
Sms_Disconnection();
return "发送成功!";
}
------解决方案--------------------
调用Sms_Send()方法时,第一个参数是手机号码,第二个是发送内容。
第一个参数是一个string型,而你传入的是一个string[]数组,所以当然错了。