×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    4

    C# sample needed to send/receive SMS

    Hi there,
    I am trying to program in C# to send/receive SMS via Nokia 6610. The version of PC Connectivity SDK is 3.0
    I will be appreciate if someone can share the C# sample to me.

  2. #2
    Regular Contributor
    Join Date
    Nov 2003
    Posts
    221
    Take this :-)
    My code. Sending only.



    /* SMS sending via PC SDK v3.0, by Zamba */

    using System;
    using NokiaCLMessaging;

    namespace SMSSend
    {
    public class SMSNokia
    {
    private ShortMsgAdapter smsObj;
    private IMemory smsMemObj;

    public SMSNokia()
    {
    smsObj = new ShortMsgAdapter();
    smsMemObj = (IMemory)smsObj;
    }

    ~SMSNokia()
    {
    smsObj = null;
    }

    // can throw COMException!
    public void SendSMS(string message, string number)
    {
    IGSMParameters parameters;
    IGSMSubmit submitObj;
    ShortMessageItem smsEntry;

    // Get parameter set
    parameters = (IGSMParameters)smsMemObj.GetParameters(ParametersType.PARAMETERS_TYPE_GSM, 1);

    // Create new short message
    smsEntry = new ShortMessageItem();
    smsEntry.Type = ShortMessageType.SHORTMESSAGE_TYPE_GSM_SUBMIT;

    submitObj = (IGSMSubmit)smsEntry.TypeProperties;
    submitObj.Message = message;
    submitObj.DestinationAddress = number;
    submitObj.ServiceCenterAddress = parameters.ServiceCenterAddress;
    submitObj.ProtocolID = parameters.ProtocolID;
    submitObj.DataCodingScheme = parameters.DataCodingScheme;
    submitObj.ValidityPeriodRelative = parameters.ValidityPeriodRelative;

    // Send message
    smsObj.SendSMS(ShortMessageRouteType.SHORTMESSAGE_ROUTE_TYPE_ANY, submitObj);
    }
    }
    }
    Last edited by Zamba; 2003-12-16 at 14:56.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    Hi Zamba,
    Thanks for your sharing. I have noticed there is no reply from the "SendSMS" method, which means I couldn't know whether the SMS has been sent successful or not. I tried to disconnect the cable between PC and my handphone, and it did not return any exception when "SendSMS" method was called! Do you know how to check whether the mothed is called successfully or not? Thanks a lot!

  4. #4
    Regular Contributor
    Join Date
    Nov 2003
    Posts
    221
    SendSMS returns void because in a normal program flow you do not need return values. Only in the case of an error a COMException is thrown by the Interop. If there's no phone, you'll get a COMException with the message "No phone connected".

    You'll get this exception already when calling the "GetParameters" method in SendSMS because the phone must be connected to get the parameter set.

    In my programs I extended this with the PhoneInfo interface (IPhoneInfo4) to detect whether the phone is really connected before attempting to call SendSMS.

    Zamba

  5. #5
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    Hi Zamba,
    Thanks for your explanation. My concern is what if the SMS can't be sent out because of the network jam. For example, at 2004 new year eve, I couldn't send SMS to my friends because too many people were using sms to celebrate the festival. I know the sending was failed because the handphone could let me know, but since the "SendSMS" method doesn't return anything, how can my application know the SMS has been sent out successfully or not if the network traffic is very high?
    I really do want to know it because my application must send every SMS successfully.

    Ade

  6. #6
    Regular Contributor
    Join Date
    Nov 2003
    Posts
    221
    I expect the SendSMS (of the smsObj) method to also to throw an exception if a network error occurs during sending. I don't know of any other way to find out if the sending failed.


    Zamba

    Last edited by Zamba; 2004-01-01 at 16:00.

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    2

    Re: C# sample needed to send/receive SMS URGENT

    Hi Zamba
    Your code works fine!!!!

    I'm using a nokia 8310 with infrared.

    I've encapsulated the code into an assembly and used it with a windows form

    The problem arrives when using a WEBFORM.

    Lack of permissions in - Solved (see next)

    "The machine-default permission settings do not grant Local Activation
    permission for the COM Server application with CLSID
    {535C2465-05B6-11D2-8C04-00A0C94C5D75}
    to the user DDWRK2005\ASPNET SID
    (S-1-5-21-1202660629-796845957-839522115-1003). This security permission can
    be modified using the Component Services administrative tool."



    But now it returns "No Phone connected"
    at this line
    // Send message
    smsObj.SendSMS(ShortMessageRouteType.SHORTMESSAGE_ROUTE_TYPE_ANY, submitObj);


    Thanks in advance

  8. #8
    Regular Contributor
    Join Date
    Nov 2003
    Posts
    221

    Re: C# sample needed to send/receive SMS

    Hi,
    thanks.

    It should be important to note that the connection manager settings affect the current user only, if you run it from a service, you may have to copy some registry entries to the account that will actually connect to the phone (ASPNET in this case). If you changed it to infrared, then under ASPNET it might still try to connect via serial for example. I just don't remember those exact keys any more, it was something below HKCU\Software\Nokia.

    Zamba

  9. #9
    Registered User
    Join Date
    Apr 2007
    Posts
    26

    Re: C# sample needed to send/receive SMS

    hello to all of you... im wondering if where can i get that v 3.0 sdk?... i am also looking sdk and code for C# and im glad i see this forum... zamba can you also share code for reciving sms, if it is ok?... thanks in advance

  10. #10
    Registered User
    Join Date
    Apr 2007
    Posts
    26

    Re: C# sample needed to send/receive SMS

    i already have the sdk v3.0... thanks again

  11. #11
    Registered User
    Join Date
    Jun 2008
    Posts
    2

    Re: C# sample needed to send/receive SMS

    Hi, Zamba,
    i saw your post regarding sending sms using NokiaCLMessaging under c#.
    i tried your code, but i always get "phone not connected" problem.
    How do you get your phone connected?
    in fact, my phone is already connected to my computer through bluetooth, it can be seen through Nokia PC Suite program.
    How did you manage to tell the code that where the phone is?

    Colin

  12. #12
    Registered User
    Join Date
    Jun 2008
    Posts
    2

    Re: C# sample needed to send/receive SMS

    Hi,
    Zamba

    Your Code made it simple how to send SMS via my phone from My PC
    Now problem is when i'm trying to connect it to my web site when i'm running the same code just by including the COM component in the devlopment stage itz working fine. But, I tried to run after deploying it is throwing an error


    Creating an instance of the COM component with CLSID {B422B592-AF13-11D4-93F9-0004AC969B31} from the IClassFactory failed due to the following error: 80004005.


    I'm using ASP.Net to develop and deploy

    Can you suggest me any solution please....

    Thanx in advance

  13. #13
    Registered User
    Join Date
    Jul 2008
    Posts
    1

    Re: C# sample needed to send/receive SMS

    Hi Zamba,

    Can you make available your code "NokiaCLMessaging namespace", where you made all NclMsg.dll imports. I didn't manage to run your sms_send sample, and I think this is the reason ?!

    Thanks,

    Marco

  14. #14
    Registered User
    Join Date
    Jul 2008
    Posts
    1

    Re: C# sample needed to send/receive SMS

    Work this code on Windows Mobile applications in C# too?
    Thanks.

  15. #15
    Registered User
    Join Date
    Oct 2008
    Posts
    1

    Re: C# sample needed to send/receive SMS URGENT

    I tried Zamba's code with nokia E51 and 5200
    I always recieves the message "No phone connected"'
    Can anyone help me pls?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •