How to send SubmitSm? (solved)

Jul 25, 2011 at 1:14 PM
Edited Jul 25, 2011 at 1:15 PM

Hi all,

Does anyone know how to send "SubmitSm" message?

SmppClient mmclient = new SmppClient();
SubmitSm mSubReq;
SubmitSmResp mSubResp;
SmppConnectionProperties properties = mmclient.Properties;

 properties.SystemID = ......;
........;
.....;
....;
......;

mSubReq.DestinationAddress.Address = "49123456789"; 
mSubReq.EsmClass = EsmClass.Default;   
mSubReq.RegisteredDelivery = RegisteredDelivery.DeliveryAcknoledgement; 
mSubReq.ServiceType = "NET"; 
mSubReq.SetMessageText("Hi, test message 1 with a new lib!", dataCoding:0); 
mSubReq.RegisteredDelivery=RegisteredDelivery.DeliveryAcknoledgement; 
// ANd what now? mmclient.SendMessage(mSubReq); // this doesn't work as the "SendMessage expects a Short message and NOT the SubmitSm!!! 
//Hence the question: how to send SubmitSM using Jamaa? 
thanks & regards 
codexer
Coordinator
Jul 25, 2011 at 10:36 PM
Edited Jul 25, 2011 at 10:41 PM

Hello Codexer,

The SmppClient class is a wrapper around the class SmppClientSession which does the job of sending the native PDU's. Every call to SmppClient that involves one or more PDUs is routed through this base library, which actually does the dirty work of translating such calls into PDU based messages.

The SmppClient class adds extra layer of insulation, so that it is possible to perform basic functions, e.g sending/receiving messages without knowing how the SMPP protocol works.

That said, if you need to go beyond what the SmppClient class provides, the best way would be to use the underlying SmppClientSession class instead.

The SmppClient class has to instances of SmppClientSession class, one for transmitting and one for receiving PDUs as shown below:

 

public class SmppClient : IDisposable {

	private SmppClientSession vTrans; //transmitter class

	private SmppClientSession vRecv; //receiver class

...

...

}

Since these instances are private, you will need to make changes to the source code and recompile the project yourself.
For example, you can add your own custom method for sending arbitrary PDU's as follows:

 
public class SmppClient : IDisposable {
....
....

	public ResponsePDU CustomSendPDU(PDU pdu) {
		return vTrans.SendPDU(pdu);
	}
}

Now, you can send arbitrary PDU's as follows:

SmppClient client = new SmppClient();
//Configure your smpp client
client.Start(); //Start smpp client

SubmitSm submitReq = new SubmitSm();
//Populate SubmitSm properties as required
SubmitSmResp submitResp = client.CustomSendPDU(submitReq) as ResponsePDU;
if(submitResp.Header.ErrorCode == SmppErrorCode.ESME_ROK) { /*Things went fine*/ }
else { /*There was an error*/ }

Hope that helps!

Ben

Jul 27, 2011 at 12:08 PM

Hi Ben,

As I'm not the best in creating new libs with COM, I see there no posibilities for me to get it working the way you wrote... :-(

Or had I have to implement your provided code in MY App?

thanks

regards

codexer

Coordinator
Jul 27, 2011 at 2:38 PM
Hello Codexer,

The library is not COM based, but rather 100% pure .NET library.

The sample compiler you use to compile your source code should be able to compile the source code out of the box without additional efforts.

Ben

On Wed, Jul 27, 2011 at 2:08 PM, codexer <notifications@codeplex.com> wrote:

From: codexer

Hi Ben,

As I'm not the best in creating new libs with COM, I see there no posibilities for me to get it working the way you wrote... :-(

Or had I have to implement your provided code in MY App?

thanks

regards

codexer

Read the full discussion online.

To add a post to this discussion, reply to this email (jamaasmpp@discussions.codeplex.com)

To start a new discussion for this project, email jamaasmpp@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Jul 28, 2011 at 9:03 AM

HI Ben,

thanks!

That means I could add mentioned code segment:

public ResponsePDU CustomSendPDU(PDU pdu) {
return vTrans.SendPDU(pdu);
}
 ... somewhere in the  SmppClient class and I will have the posibility to send submitsm ?

If yes, there is nothing easier than that! :-)

Additional question 1:  there are only two binds possible. what about TRX ( transceiver)?

private SmppClientSession vTrans; //transmitter class
private SmppClientSession vRecv; //receiver class

Should I add following code to the SmppClient class ( or where?) to get the posibiliti to use TRX?:

private SmppClientSession vTransc; //transceiver class  

Additional question 2: I tried to bind to the SMSC, it works of course :-), but I saw that my client has been connected to the SMSC as TRX, without to define it explicit manualy. How can I define the bind type (RX or TX or TRX) while using this client?

Additional question 3: I'm going to use optional parameters while sending the msg (using submitsm). But I don't want to use the standard ( smpp specs 3.4) TLVs. I would like to use, on example in other smpp LIBs one can set the TLV ads following:

submit_sum.SetOptionalParamString(0x2646, "22164"); // 0x2646 is pointing to key: 9798 and has a value (it can be string or int): 22164.

//or so ( other LIB):

ASCIIEncoding EncForTlv = new ASCIIEncoding(); // C# encoding...
SmppTlv.Tag TLV_APP_ID = new SmppTlv.Tag(0x2646); //Create new TLV
byte[] mTlvValue = EncForTlv.GetBytes("22164"); //store the bytes from value 22164 to a bytearray mTlvValue
TLV_APP_ID.SetByteArray(mTlvValue); // add this bytearray to the new created TLV
ReqSubmit_Sm.Tlv.AddTlv(TLV_APP_ID); // add this new TLV to the submitsm

And here my code segment of using your LIB. Please modify ( if possible) some code rows to give me the posibility to: 1. chose the type of bind while connectin to the SMSC, 2. Add optional parameters.:

using System;
using System.Net;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JamaaTech;
using JamaaTech.Smpp;
using JamaaTech.Smpp.Net;
using JamaaTech.Smpp.Net.Lib;
using JamaaTech.Smpp.Net.Client;
using JamaaTech.Smpp.Net.Lib.Networking;
using JamaaTech.Smpp.Net.Lib.Protocol.Tlv;
using JamaaTech.Smpp.Net.Lib.Protocol;
using JamaaTech.Smpp.Net.Lib.Util;


namespace MMJamaa 
{
    public partial class Form1 : Form
    {      
        SmppClient mmclient; 
        SmppConnectionProperties properties;
        InterfaceVersion mintv = InterfaceVersion.v34;
        JamaaTech.Smpp.Net.Lib.Protocol.CommandType mcmType; // how to choose the transceiver???
        JamaaTech.Smpp.Net.Client.SmppConnectionState mconnst;
        TextMessage mmsg; 
         
        public Form1()
        {
            InitializeComponent();
              
        }

        private void button1_Click(object sender, EventArgs e)
        {
            mcmType = JamaaTech.Smpp.Net.Lib.Protocol.CommandType.BindTransmitter; // how to use it? add to client? no possible! TRX???
            mmclient = new SmppClient();
            properties = mmclient.Properties;
            
            properties.SystemID = "mysystemid";
            properties.Password = "mypwd";
            properties.Port = 1234; //IP port to use
            properties.Host = "123.456.789.999"; //SMSC host name or IP Address
            properties.SystemType = "NET";
            properties.InterfaceVersion = mintv;
            properties.DefaultServiceType = ServiceType.DEFAULT;
            properties.DefaultEncoding = DataCoding.SMSCDefault;
            properties.AddressNpi = NumberingPlanIndicator.Unknown;
            properties.AddressTon = TypeOfNumber.Unknown;

            //Resume a lost connection after 30 seconds
            mmclient.AutoReconnectDelay = 3000;
            //Send Enquire Link PDU every 29 seconds
            mmclient.KeepAliveInterval = 29000;         
            //Start smpp client
            mmclient.Start();
            //get the state
            mconnst = mmclient.ConnectionState;
            // show output in a textbox
            richTextBox2.Text = mconnst.ToString();
        }

      

        private void button2_Click(object sender, EventArgs e)
        {
            mmsg = new TextMessage();
            mmsg.DestinationAddress = "431234567890";
            mmsg.RegisterDeliveryNotification = true;
            mmsg.SourceAddress = "430987654321";
            mmsg.Text = "My first sent msg using this LIB, will see how it wors...";
            mmclient.SendMessage(mmsg);

        }

        private void button3_Click(object sender, EventArgs e)
        {
            mmclient.Shutdown();
            
            richTextBox2.Text = mconnst.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {

        }
    }
}

thanks Ben!!!

cheers

codexer 

 



Jul 28, 2011 at 10:27 AM

Hi Ben,

 

I added the code rows( how you said):

public class SmppClient : IDisposable {
....
....

	public ResponsePDU CustomSendPDU(PDU pdu) {
		return vTrans.SendPDU(pdu);
	}
}

But i get the error while adding this code to the SmppClient:

"No definition for SendPDU and no extension method has been found to order to accept the first argument" ( has been translated from german to english from my side :-))

what is wrong there and what is missing?

Could you please provide full details how to do that?

thanks

cheers

codexer

Coordinator
Jul 29, 2011 at 11:54 AM

Hello Codexer,

Sorry, my previous posting was somehow misleading.

Please change the code snippet where it reads:

return vTrans.SendPDU(pdu);

to:

return vTrans.SendPdu(pdu);

Note change in casing.

By default, Jamaa SMPP Client library binds as TRX using ver 3.4 protocol. To change this behavior, change the interface version to version 3.3 as shown below:

 

SmppClient client = new SmppClient();

SmppConnectionProperties prop = client.Properties;

prop.InterfaceVersion = InterfaceVersion.v33;

//Specify other connection details here

 

You can Tlv to Pdu's using the Tlv class (Remember to declare the namespace JamaaTech.Smpp.Net.Lib.Protocol.Tlv).

Keep in my that, you will need to provide proper encoding for all Tlv values. The class SMPPEncodingUtil offer various methods for encoding/decoding common .NET type to/from raw bytes.

The code snippet below shows how you can use Tlv to define custom behaviors or provide additional data to PDU's:

//Don't forget to include the following namespaces
using System;
using JamaaTech.Smpp.Net.Lib;
using JamaaTech.Smpp.Net.Lib.Protocol;
using JamaaTech.Smpp.Net.Lib.Util;
using JamaaTech.Smpp.Net.Lib.Protocol.Tlv;

 

Here goes the source code

 

//Your code starts here

string tlvValue = "938838383"; //This is my tlv value

byte[] tlvBytes = SMPPEncodingUtil.GetBytesFromString(tlvValue); //Convert the string to bytes to use with Tlv

Tlv tlv = new Tlv(Tag.dest_subaddress, 0); //You can define the tag lengh here or specify zero instead. We will provide the length value latter on

tlv.ParseValue(tlvBytes); //This will automatically set the Tlv length to size of the array.

//Now that we have defined the Tag, Length and Value, our Tlv is ready for use

SubmitSm pdu = new SubmitSm();

pdu.Tlv.Add(tlv);//Add the tlv to the pdu

//Specify other details

//Send the pdu


 

Jul 29, 2011 at 1:11 PM

Hi Ben,

Thank you for provided info.

I'll try to implement it correct now.

BTW: Is there a posibility to modify the smppclient lb to get the choosing of bindtype?

If yes,  and there isn't to mutch to "experiment" with that :-) , please provide the solution ( code change or code add ? ) and I'll try to modify  this lib.

thanks Ben, nice to have someone who responses on my requests imidiately. :-)

I'll let you know what's the outcome of my tests.

regards

Codexer

 

Jul 29, 2011 at 2:45 PM

Hi Ben,

Tried again...

changed following (this is a part of code in SmppClient.cs, just that you know where I added this code segment :-) ):

       public void EndSendMessage(IAsyncResult result)
        {
            vSendMessageCallBack.EndInvoke(result);
        }

        /// <summary>
        /// Sends message to a remote SMMP server using SubmitSM (seems not to work as expected)
        /// </summary>
        public ResponsePDU CustomSendPDU(PDU pdu) // added this function according to Ben
        {
           // return vTrans.SendPDU(pdu); // was wrong according to Ben
            return vTrans.SendPdu(pdu);   // seems to be wrong also :-(
        }

        public void Start()
        {

            vStarted = true;
            vTimer.Change(0, vAutoReconnectDelay);
            RaiseStateChangedEvent(true);
        }

        /// <summary>
        /// Starts <see cref="SmppClient"/> and waits for a specified amount of time before establishing connection
        /// </summary>
        /// <param name="connectDelay">A value in miliseconds to wait before establishing connection</param>
        public void Start(int connectDelay)
        {
Now I have following error while compiling this Lib: ( translated from DE to EN):
 (DE): "1-Argument: Kann nicht von "JamaaTech.Smpp.Net.Lib.Protocol.PDU" in "JamaaTech.Smpp.Net.Lib.Protocol.RequestPDU" konvertiert werden."
     reason: (DE): "Die beste Übereinstimmung für die überladene JamaaTech.Smpp.Net.Lib.SmppClientSession.SendPdu(JamaaTech.Smpp.Net.Lib.Protocol.RequestPDU)-Methode 
                    hat einige ungültige Argumente."
 (EN):"1-Argument: Could not convert from "JamaaTech.Smpp.Net.Lib.Protocol.PDU" in "JamaaTech.Smpp.Net.Lib.Protocol.RequestPDU".
    reason: (EN): The best match for overloaded method JamaaTech.Smpp.Net.Lib.SmppClientSession.SendPdu(JamaaTech.Smpp.Net.Lib.Protocol.RequestPDU) does have some not valid arguments.
Seems not to be the solution... any other chance to get the submitsm? If you hav 5 minutes time you could "produce" this error yourself while adding mentioned code segment to the SmppClient.cs
Please advise what I have to do to get it working. 
thanks Ben
nice weekend
Codexer 
Coordinator
Jul 31, 2011 at 7:57 PM

Hi Codexer,

Please replace PDU with RequestPDU in the CustomSendPDU parameter.

With regard to changing the binding type, please see my previous post.

Ben

Aug 1, 2011 at 8:24 AM

Hi Ben,

thanks...

will see how it works....

reg

Codexer

 

Aug 1, 2011 at 4:26 PM
Edited Aug 1, 2011 at 4:27 PM
 

Hi Ben,

 

Thanks for your help in this case. I was able to reach the end point of this problem. I'll try to describe here the steps which are necessary to get the Jamaa libs to send custom pdu / submitsm and TLVs. I think this could help other people who are interesting in this project.   First we had a problem with SubmitSM funktion. this funktion was available in the lib but there were no explaining how to use it or (and) there was a missing method which could use this funktion. If somebody needs the "SubmitSM" he should do following: 

  Add this code segment somewhere in the SmppClient.sc:

 public ResponsePDU CustomSendPDU(RequestPDU pdu)
        {
            return vTrans.SendPdu(pdu);
        }

 How to use it:

SmppClient mmclient = new SmppClient(); 
         SmppConnectionProperties properties = new SmppConnectionProperties();
         InterfaceVersion mintv = InterfaceVersion.v34;
         SmppConnectionState mconnst = new SmppConnectionState();
         SubmitSm mSubmitSM = new SubmitSm(); 
         SubmitSmResp msubmitResp;

// other settings:
 mSubmitSM.DestinationAddress.Address = "49123456789";
            mSubmitSM.DestinationAddress.Npi = NumberingPlanIndicator.Unknown;
            mSubmitSM.DestinationAddress.Ton = TypeOfNumber.Unknown;
            mSubmitSM.EsmClass = EsmClass.Default;
            mSubmitSM.RegisteredDelivery = RegisteredDelivery.DeliveryReceipt;
            mSubmitSM.ServiceType = "CMT";

//And send message:
 msubmitResp  = mmclient.CustomSendPDU(mSubmitSM) as SubmitSmResp;

 And here is the definition how to use the TLVs. please note that I was not satisfied with the TLVs provided in the smpp specs 3.4 I have had to use some add. TLV like e.g 0x2646 ( pointing to key 9798). This was not provided in 3.4 therefore I modified the "JamaaTech.Smpp.Net.Lib.v1.4". I added this Tag as following to the "Tag.cs":

tlv_app_id = 0x2646

  After that I was able to use this Tag and , (thanks to Ben !!!) using following code my add. optional parameter has been added to the SubmitSM:

            string tlvValue = "22164"; //This is my tlv value
            byte[] tlvBytes = SMPPEncodingUtil.GetBytesFromString(tlvValue); //Convert the string to bytes to use with Tlv
            Tlv TLV_APP_ID = new Tlv(JamaaTech.Smpp.Net.Lib.Protocol.Tlv.Tag.tlv_app_id, 0); // create new Tag (was not in the smpp 3.4)
            TLV_APP_ID.ParseValue(tlvBytes); // add the value 22164 to this Tag
            mSubmitSM.Tlv.Add(TLV_APP_ID); //add the TLV to the submitsm

 

Thanks to Ben who was so kind and provided a big help to solve this problem !!!

adio

codexer        

                           

Coordinator
Aug 1, 2011 at 9:13 PM

Hi Codexer,

Nice to hear that it finally worked.

Please, don't forget to rate our Jamaa SMPP Library.

Ben