none
how to send sms to any number from wpf application?

    Question

  • hi,

    I have application in wpf, and I want to send sms to any mobile number, I am able to send sms to any no. using sms gateway

    but I don't want force to my client to use same sms gateway, I mean he can choose any sms gateway,

    So I want to design code that can use for any sms gateway, how can do this, 

    any one have some idea on this, please help me.

    thanks


    Sushil Bhat

    Wednesday, April 12, 2017 5:33 AM

All replies

  • You can create common interface as suggested in following link. But most sms gateway providers provide you API through which you can send sms. So you still would have to do integration based on provider your client chooses.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/7844035e-60db-4a22-87bd-d4e8363c2e2f/how-to-send-sms-from-wpf-application?forum=wpf


    Gaurav Khanna | Microsoft MVP | Microsoft Community Contributor

    Wednesday, April 12, 2017 5:46 AM
  • Thanks Gaurav,

    But I din't find any help from these link,


    Sushil Bhat

    Wednesday, April 12, 2017 9:54 AM
  • The point is that there is unfortunately no international standard for this (that I know of).

    Every SMS provider provides their own API, often a webservice, that you use to send the SMS.

    Given this, it probably will not be possible to write one piece of code that will just magically work with every sms gateway provider.

    The best you could do would be to implement a facade pattern of some kind, i.e. you write some code that wraps a common interface that has descendent classes for specific providers. For more flexibility, and to avoid needing to distribute your entire application if you need to support a new provider, implement some kind of plugin architecture.

    That way, if someone wants to use a different provider you just write and distribute a new plugin assembly.


    • Edited by RJP1973 Wednesday, April 12, 2017 10:05 AM
    Wednesday, April 12, 2017 10:05 AM
  • Thanks RJP1973

    I completely agree with you that

     

    no international standard for this 

    Every SMS provider provides their own API, often a webservice, that you use to send the SMS.

    Given this, it probably will not be possible to write one piece of code that will just magically work with every sms gateway provider.

    as you told The best you could do would be to implement a facade pattern of some kind, i.e. you write some code that wraps a common interface that has descendent classes for specific providers. For more flexibility, and to avoid needing to distribute your entire application if you need to support a new provider, implement some kind of plugin architecture.

    can you have some piece of code so I will get clear picture.

    thakns


    Sushil Bhat

    Wednesday, April 12, 2017 10:27 AM
  • Here is a general example of a plugin architecture in C#, or just search for "C# plugin architecture".

    Just summarising the examples, you would create interface(s) in a separate assembly that will be shared between both your main app and your plugin libraries. For example:

    public ISmsMessage
    {
       string PhoneNumber {get;set;}
       string Message {get;set;}
    }
    
    public ISmsGateway
    {
       public void SendSms(ISmsMessage);
    }

    You would then create a separate plugin library (probably one for each sms gateway) that references your shared library and contains a class that implements ISmsGateway.

    Your main app would need some way of knowing what plugin libraries are available, possibly through config or by just looking in a known plugin folder and using reflection to pick up the classnames from the assemblies.

    When necessary, the main app can then dynamically create an instance of an appropriate gateway class using something like:

    string ClassName="Mystuff.MyPlugin, MyPlugin"; 
    
    ISmsGateway gateway = (ISmsGateway)Activator.CreateInstance(Type.GetType(ClassName));

    (This is all very rough, but just follow the link at the top or search as suggested and you will find plenty of full examples).
    Wednesday, April 12, 2017 11:01 AM