none
system.net namespace SMS RRS feed

  • Question

  • I wrote a visual studio VB project to send sms messages via a clickatell account. Using the system.net namespace. How can I do this in lightswitch? I tried to import system.net namespace but it was not recognised. Can anyone help please?
    Dim client As WebClient = New WebClient
    
                ' Add a user agent header in case the requested URI contains a query.
    
                client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)")
    
                client.QueryString.Add("user", ClickUname)
                client.QueryString.Add("password", ClickPwd)
                client.QueryString.Add("api_id", ClickatellAPI)
    
                client.QueryString.Add("from", "********")
    
                client.QueryString.Add("to", phoneno)
    
                client.QueryString.Add("text", msg)
    
                Dim baseurl As String = "http://api.clickatell.com/http/sendmsg"
    
                Dim data As Stream = client.OpenRead(baseurl)
    
                Dim reader As StreamReader = New StreamReader(data)
    
                Dim s As String = reader.ReadToEnd()
    
                data.Close()
                reader.Close()
    
                Return
    

    _
    Sunday, October 9, 2011 11:55 PM

Answers

  • Please don't take this the wrong way, Did you add the reference to the solution for the assembly.
    http://www.virtualrealm.com.au - SQL Server DBA, MVP and Lightswitch Enthusiast.
    • Marked as answer by zippydippyDO Friday, November 4, 2011 9:22 AM
    Monday, October 10, 2011 12:04 AM
  • This post provides some good information on the Command Table Pattern:

    http://social.msdn.microsoft.com/Forums/en-US/lightswitchgeneral/thread/91031b6a-59b5-4f2f-a43c-772d90e33d4a

     

    Take care,

    Dave

    • Marked as answer by zippydippyDO Friday, November 4, 2011 9:23 AM
    Tuesday, October 11, 2011 12:52 AM
  • No problem. You're welcome, of course!

    Yann

    (plus ça change, plus c'est la même chose!)

    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    This will help people find the answers that they're looking for more quickly.

    • Marked as answer by zippydippyDO Friday, November 4, 2011 9:23 AM
    Monday, October 17, 2011 10:51 PM
    Moderator
  • You're probably trying to add the code to the "Client" project, you'll need to add it to the "Server" project, as System.Net is not implemented by Silverlight, only in the full .NET framework.

    You won't be able to "initiate" the code directly from anything on the client, like a screen button, you'll need to use something like what's been referred to as the "Command Table Pattern", where you add a record to the table, & intercept the Save Pipeline (using EntityName_Saving), then "trigger" the SMS code from there.


    Yann

    (plus ça change, plus c'est la même chose!)

    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    This will help people find the answers that they're looking for more quickly.

    • Marked as answer by zippydippyDO Friday, November 4, 2011 9:23 AM
    Monday, October 10, 2011 12:18 PM
    Moderator
  • Hi Richard,

    Sorry, what I should have said is that a lot of the functionality of System.Net is not implemented in Silverlight, not that System.Net itself wasn't, which is why you're not seeing the methods that you're looking for, even though you've now managed to add a reference to System.Net.

    Silverlight does not expose ALL of the same functionality that the full .NET Framework does.

    In a LightSwitch app, most of the projects are Silverlight projects, so the code you can use in them is restricted to what's avauilable in Silverlight, but the "Server" project is a .NET project, so you can use the full unrestricted framework code in it.

    The trouble is that, even in a desktop app, you can't access this "server" code directly from the "client" (like in a screen), so you have to use "tricks" like I mentioned previously. A LightSwitch app is architected to be split into the same "tiers", whether it's being run on a destop, or on a web server.

    I'm *really* sorry, but I just don't have the time right now to go into details of the "Command Table Pattern". You can either search this forum for some more details (it's been mentioned frequently), or someone else will come along & explain it I'm sure.


    Yann

    (plus ça change, plus c'est la même chose!)

    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    This will help people find the answers that they're looking for more quickly.

    • Marked as answer by zippydippyDO Friday, November 4, 2011 9:23 AM
    Monday, October 10, 2011 11:57 PM
    Moderator

All replies

  • Please don't take this the wrong way, Did you add the reference to the solution for the assembly.
    http://www.virtualrealm.com.au - SQL Server DBA, MVP and Lightswitch Enthusiast.
    • Marked as answer by zippydippyDO Friday, November 4, 2011 9:22 AM
    Monday, October 10, 2011 12:04 AM
  • You're probably trying to add the code to the "Client" project, you'll need to add it to the "Server" project, as System.Net is not implemented by Silverlight, only in the full .NET framework.

    You won't be able to "initiate" the code directly from anything on the client, like a screen button, you'll need to use something like what's been referred to as the "Command Table Pattern", where you add a record to the table, & intercept the Save Pipeline (using EntityName_Saving), then "trigger" the SMS code from there.


    Yann

    (plus ça change, plus c'est la même chose!)

    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    This will help people find the answers that they're looking for more quickly.

    • Marked as answer by zippydippyDO Friday, November 4, 2011 9:23 AM
    Monday, October 10, 2011 12:18 PM
    Moderator
  • Hi Glenn,  No problem I am a novice!  I did discover the Project - Add Reference and found the System.Net namespace.   Imported it fine.  But then all the members seem not to be present e.g.

    Headers.Add

    QueryString.Add

    Any ideas

     

    Richard

     


    richard
    Monday, October 10, 2011 11:07 PM
  • WOW Yann that sounds great...but to be honest I dont really understand your answer at all.  My application will run on my local PC.

     

    I forgot to add the Profject-Add referecne and found the System.net namespace....but the Headers.Add and Querystring.Add are not apparently memebers of the namespace...unlike in VB.net

    What you help please in simple terms please :)

     

     


    richard
    Monday, October 10, 2011 11:09 PM
  • Hi Richard,

    Sorry, what I should have said is that a lot of the functionality of System.Net is not implemented in Silverlight, not that System.Net itself wasn't, which is why you're not seeing the methods that you're looking for, even though you've now managed to add a reference to System.Net.

    Silverlight does not expose ALL of the same functionality that the full .NET Framework does.

    In a LightSwitch app, most of the projects are Silverlight projects, so the code you can use in them is restricted to what's avauilable in Silverlight, but the "Server" project is a .NET project, so you can use the full unrestricted framework code in it.

    The trouble is that, even in a desktop app, you can't access this "server" code directly from the "client" (like in a screen), so you have to use "tricks" like I mentioned previously. A LightSwitch app is architected to be split into the same "tiers", whether it's being run on a destop, or on a web server.

    I'm *really* sorry, but I just don't have the time right now to go into details of the "Command Table Pattern". You can either search this forum for some more details (it's been mentioned frequently), or someone else will come along & explain it I'm sure.


    Yann

    (plus ça change, plus c'est la même chose!)

    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    This will help people find the answers that they're looking for more quickly.

    • Marked as answer by zippydippyDO Friday, November 4, 2011 9:23 AM
    Monday, October 10, 2011 11:57 PM
    Moderator
  • Ok ZippyDippy

    What is Yann talking is:

    Crate entity called SMS with properties:

    • Id (integer)  -this property is autoamtically created by LightSwitch
    • PhoneNumber (PhoneNumber)
    • Body (String) - text of sms
    • Created (DateTime) - when sms is created
    • CreatedBy (String) - who created sms

    or use other properties that you want.

    Than you need to use method witn SMS entity that is generated on server side. If you select entity by clicking on entity header (where is text SMS on entity) then go to Write Code and then choose method SMSSet_Inserted.

    Noted that SMSSet is plural of you SMS entity. If you hover over SMSSet_Inserted method note explanation:

    As Yann explained, you need to use method that runs on server side. Now, you don't need to include System.net as you have namespace System.net in your server project (Swittch to File View instead of Logical view with File View/Server/Properties note that you have in Imported namespaces: System.net). Now, just write your code:

    Private Sub SMSSet_Inserted(entity As SMS)
    	Dim client As WebClient = New WebClient
    	client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)")
    	'Code here
    End Sub
    

    So, as Yann said, you can't use CreateNewSMS screen and use button in this screen to use code for sending SMS because button is fired on client side.

    Hope this help

    Spaso Lazarevic

     

    Tuesday, October 11, 2011 12:34 AM
  • This post provides some good information on the Command Table Pattern:

    http://social.msdn.microsoft.com/Forums/en-US/lightswitchgeneral/thread/91031b6a-59b5-4f2f-a43c-772d90e33d4a

     

    Take care,

    Dave

    • Marked as answer by zippydippyDO Friday, November 4, 2011 9:23 AM
    Tuesday, October 11, 2011 12:52 AM
  • Hey Yann

     

    THat was very helful indeed and I appreciate you 'dumbing' it down for me.  great!

     

    Richard


    richard
    Friday, October 14, 2011 7:10 PM
  • Wow...that sounds great..  I will try this code

     

    thanks very much

     

    Richard


    richard
    Friday, October 14, 2011 7:10 PM
  • No problem. You're welcome, of course!

    Yann

    (plus ça change, plus c'est la même chose!)

    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    This will help people find the answers that they're looking for more quickly.

    • Marked as answer by zippydippyDO Friday, November 4, 2011 9:23 AM
    Monday, October 17, 2011 10:51 PM
    Moderator