Development of business process applications that enable SMS

xiaoxiao2021-03-06  39

Suitable for: Microsoft® .NET Compact Framework Microsoft Visual Studio® .NET Microsoft Windows® Powered Pocket PC Phone

Summary: As a senior member of the mobile phone family, Windows Power Pocket PC Phone with built-in telephone features has multiple connection options. The core function is available to the Internet, in addition to this, there are other available options. In all Global Mobile Communications Systems (GSM) networks, a commonly used communication method is to use a Short Message Server (SMS) message. This is an option that cannot be ignored when designing the mobile phone application, which will be explained herein. (This article also includes English links. Please note that in the sample file, the programmer's comment is in English. In this paper, it is translated into Chinese to facilitate the reader.)

Download SMS_APPS.exe

table of Contents

What is SMS? Why use SMS? SMS APISMS AnyPlace sample code drill summary

What is SMS?

The short message server enables mobile phones (including Pocket PC Phone) to send short messages using GSM networks, which have many interesting features:

One SMS message can include 160 characters (even binary). SMS is a storage and forwarding service. That is, the short message is not sent directly from the sender to the recipient, but always forwards through the SMS center. If the recipient is in an unconnected state (possibly the phone is turned off), the message will be sent again when the recipient is again connected. SMS has a message to send a confirmation. This means that the SMS is different from the page, the user does not simply send a short message and then believes that the message has been sent success; but the short message sender can receive the return message, inform them that the short message has been sent successfully. The transmission and reception of the SMS message can be synchronized with GSM voice. The SMS message is charged by message, so it is much more expensive than the data sent by IP-based networks (for example, using GPRS [General Packet Wireless Service]).

To use SMS, users need to book mobile networks that support SMS and must be used for the user to enable SMS. The user needs to have a destination that sends a short message or receives a short message. This destination is usually other mobile phones, but it can also be a server. Finally, users also need mobile phones that support SMS and need to know how to send or read short messages using their specific models of mobile phones.

Why use SMS?

For application developers, instant solution connecting Pocket PC Phone to the server may be by IP-based networks, such as Internet. The advantages of this approach include: There are already public standard protocols, and communication tools are also ready.

However, in some cases, IP-based networks are not the most effective way of transport. Active or even automatically connects to occupy valuable time, and cannot be connected when calling. What will be what is the way to instantly connect to a server even when a call is in a call? Since the Pocket PC Phone can send SMS messages, it may be an implementation.

The instant connection is very useful when you want to inform the business process application to notify the business process application. It may be that the server has a new order salesman, or the truck driver just sent to the goods.

In terms of server, there are a variety of solutions to receive SMS messages and forward them to other systems. For example, Mobilesys, Inc. and SmartServ Online, Inc. products. In this article, we will further explore the SMS performance of Pocket PC Phone. SMS API

On the Pocket PC Phone, you can use a large number of Microsoft® Windows® CE API calls to access the SMS message function:

Function Description SMSopen opens the SMS message component for transmitting and / or receiving access. SMSsendMessage sends SMS messages. SMSgetMessageStatus retrieves the status report for sent messages. SMSReadMessage reads previously received SMS messages. SMSgetMessagesize determines the upper limit of the buffer size. SMSGETSMSC reads the default Short Message Service Center (SMSC) address. SMSsetSMSC Sets the default SMSC. SMSGETPHONENUMBER gets the phone number of the device associated with the SMS holder. SmsgetTime Gets the current time roughly estimated by the SMSC clock. SMSGetBroadcastMsgranges Get the range of broadcast messages that the mobile phone can listen. SMSSetMessageNotification launches the application when the SMS message arrives. SMSCLEARMESSAGENOTIFICATION cancels registration of SMS notification. SMSsetBroadcastMsgranges Sets the range of broadcast messages that the mobile phone can listen. SMSCLOSE closes an existing SMS message handle.

The session starts with SMSopen, which will return a SMS handle, which will be required to call the SMS API function. Terminate the session by passing this handle to SMSClose. This article focuses on the SMSsendMessage API that uses the .NET CF in the platform calling function, similar techniques can also be used to access other APIs.

SMS AnyPlace example

This example is an example application using the Pocket PC Phone created by Microsoft Visual Studio® .NET, C #, and .NET Compact Framework. It demonstrates how to send SMS messages using the SMS API. The app contains a form:

Figure 1: SMS AnyPlace example

The concept of this example is that the delivery of the truck driver does not need to connect to any IP-based network (e.g., Internet) to send a notification to a business process application on the server instantly to the server.

Imagine, make a selection in the list of goods, and subsequent screens will display the selected goods identity and the current date and time. Just tap the "Send" button.

When the "Send" button is tapped, the sending information will be compiled into an XML message string that you can see the string at the lower half of the screen. This information may not be displayed in the actual application where it is only for convenience of explanation. The XML format ensures that the receiving server can access information in standard mode. Then there is no need to connect, even if you do not need to interrupt the ongoing voice conversation, you can send XML to the server using SMS.

Code drill

Let us start from the code represented by the "Send" button:

// Create an XML message

MemoryStream MS = New MemoryStream ();

XmlTextWriter XMLW = New XMLTextWriter (MS, System.Text.Encoding.utf8);

XMLW.writestartDocument ();

XMLW.WriteStartElement ("Delivery");

XMLW.WriteElementstring ("packageid", lblpackageid.text);

XMLW.WriteElementstring ("Delivered", txtdelivered.text); xmlw.writeEndelement ();

XMLW.WriteEndDocument ();

XMLW.Flush ();

Ms.seek (0, seekorigin.begin);

StreamReader SR = New StreamReader (MS);

TXTMESSAGE.TEXT = Sr.Readline ();

lblMessage.Text = "Message (" txtMessage.text.length.tostring () "

Chars): ";

THIS.REFRESH ();

XMLW.Close ();

sr.close ();

// send messages

IF (0 == SMSHELPER.SENDSMS (" 1555550123", txtMessage.text))

Messagebox.show ("Message Sent!", This.text, MessageboxButtons.ok,

MessageBoxicon.exclamation, MessageBoxDefaultButton.Button1);

Else

MessageBox.show ("Could Not send Message!", This.text);

The goods identification and delivery time will be converted to XML. The .NET CF has local support for XML and has several classs that can be used. In this example, the XMLTextWriter class is selected. Write XML to the memory stream using a simple method. The flow is then reset to the beginning and is read from the streamreader to the message text control. The message tag is also updated with the message length. After creating a message, the message will be sent (second parameters) to the static SendSMS method for the SMShelper class. The first parameter is the target address (phone number) in the international format.

The SMShelper class begins with multiple declarations:

Private const string sms_msgtype_text = "Microsoft Text SMS Protocol";

PRIVATE CONST INT SMS_MODE_SEND = 2; // Open in Send Mode

Private const Int smsde_gsm = 1; // Using GSM encoding

Private const Int smsat_international = 1; // International format

Private const INT PS_MESSAGE_OPTION_NONE = 0; // No message option

Private const INT PS_MESSAGE_CLASS0 = 0; // Show but not store

Private const INT PS_MESSAGE_CLASS1 = 1; // Store and display

Private const INT psro_none = 0; // No replacement

Private const Int sms_option_delivery_none = 0; // No send option

[DLLIMPORT ("SMS.DLL")]]]]

Private static extern int smsopen

String PTSMessageProtocol,

INT dwmessagemodes,

Ref Intptr psmshhandle,

INT phimentageavailableeevent; [DLLIMPORT ("sms.dll")]]

Private static extern int smssendmessage

INTPTR SMSHHANDLE,

Int psmsmasmscaddress,

INTPTR PSMSADESTINATIONADDRESS,

INT PstvalidityPeriod,

INTPTR PBDATA,

INT DWDATASIZE,

INTPTR PBPROVIDERSPECIFICDATA,

INT DWPROVIDERSPECIFICDATASIZE,

Int smsdedataEncoding,

Int dwoptions,

INT psmsmidMessageID;

[DLLIMPORT ("SMS.DLL")]]]]

Private static extern int smsclose (INTPTR SMSHHANDLE);

First, declare some SMS API specific constants. This is just part of the available constant. For all constants, see the Windows CE API documentation. Each SMS API is then declared using a DLLIMPort property pointing to the DLL (dynamic link library) that performs functions in the System.Runtime.InteropServices named space (SMS.DLL in this example).

The core content of the Sendsms method is as follows:

// get a handle

IF (0! = smsopen (SMS_MSGTYPE_TEXT, SMS_MODE_SEND, REF SMSHANDLE, 0))

ReturnValue = -1; // Unable to open

// send messages

IF (0! = SMSsendMessage (smshandle, 0, smsaddress, 0,

SMSMessage, SMSMessagetag.length,

SMSProviderData, SMSProviderDataTaG.Length,

SMSDE_GSM, SMS_OPTION_DELIVERY_NONE, 0))

ReturnValue = -2;

// Release the handle

IF (0! = SMSClose (smshandle))

ReturnValue = -3; // Unable to close

The call to the SMSOpen API will set the SMS API handle (SMSHandle) and specify the type of message and send mode. Sector and other required parameters (SMSADDRESS, SMSMESSAGE, and SMSPROVIDERDATA) are declared as INTPTR. INTPTR is a structure that ensures that the length of the pointer (32-bit or 64 bits) is adapted to the local pointer size of the current platform. Finally, the SMS API handle is released by calling the SMSClose API.

summary

Since Pocket PC Phone is an important member of a mobile phone family, we can use its function, such as SMS messages. Don't forget this interesting option when designing a connection application.

转载请注明原文地址:https://www.9cbs.com/read-68108.html

New Post(0)