Click here to Skip to main content
16,020,261 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Cannot seem to find an application to work under VB.NET... Asking bandwidth.com for samples in VB.NET seems to go nowhere... Anyone out there that has a working sample using bandwidth.com as the provider for SMS sending???

Thanks for anyone's assistance.

What I have tried:

Various VB.NET shells but no luck... I would have to think someone in the community has interfaced into bandwidth.com and has an idea on getting it to work with VB.NET.
Posted
Updated 12-Oct-23 11:06am
v2

Here is the location of their api documentation: Bandwidth API Documentation[^] or more specifically, Messaging[^].

Here is a link to their C# SDK with sample code (from the links above): GitHub - Bandwidth/csharp-sdk: C# SDK for Bandwidth Voice & Messaging[^] and more code samples here: Bandwidth Samples · GitHub[^]

There are no VB.Net-specific examples that I could see. You can use ChatGPT to convert the C# into VB.Net. You can ask it to:
Convert the following C# code to VB.Net:
Then add the code to be converted. It does a better job than any tool out there that performs this specific task however it is not always 100% accurate. It is enough to point you in the right direction.

For example, if I ask it:
Convert the following C# code to VB.Net:

using Bandwidth.Standard;

var client = new BandwidthClient.Builder()
    .Environment(Bandwidth.Standard.Environment.Production)
    .MessagingBasicAuthCredentials("username", "password")
    .VoiceBasicAuthCredentials("username", "password")
    .TwoFactorAuthBasicAuthCredentials("username", "password")
    .WebRtcBasicAuthCredentials("username", "password")
    .Build();

The output is:
Imports Bandwidth.Standard

Dim client = New BandwidthClient.Builder() _
    .Environment(Bandwidth.Standard.Environment.Production) _
    .MessagingBasicAuthCredentials("username", "password") _
    .VoiceBasicAuthCredentials("username", "password") _
    .TwoFactorAuthBasicAuthCredentials("username", "password") _
    .WebRtcBasicAuthCredentials("username", "password") _
    .Build()
 
Share this answer
 
Comments
John Pope 2023 11-Oct-23 9:35am    
Oh Geez, sorry folks while I know there are samples in C# our codebase is in VB.Net so if there was anyone that can run this thru AI would be greatly appreciated, sorry a real novice here... We had gotten a sample codebase from other carriers in VB.NET and we can take it from there but converting C# to VB.Net via AI is going to be a challenge for me here... Appreciate the assistance... Once I have a working codebase in VB.Net I should be able to get it working from there... I am surprised that Bandwidth.com does not have any VB.Net sample code 🙁
Graeme_Grant 11-Oct-23 10:06am    
The sample code is there, just in C#. I've shown you how to do convert it to VB.Net, and do it quickly. Now, it is up to you to do the work required. It's called programming.

If you want someone to write code for you, then there are these services:
* fiverr[^]
* Upwork[^]
* Freelancer[^]
* Guru[^]
* PeoplePerHour[^]
* TaskRabbit[^]
* Karat[^]
Here is a Vb.NET Sample to send an SMS via Bandwidth using the System.net library

VB.NET
Imports System
Imports System.ComponentModel
Imports System.IO
Imports System.Net
​
Module Program
    Sub Main(args As String())
        SendSMS()
    End SubPublic Sub SendSMS()
        Try
            Dim myReq As HttpWebRequest
            Dim myResp As HttpWebResponse
            Dim myReader As StreamReader
            myReq = HttpWebRequest.Create("https://messaging.bandwidth.com/api/v2/users/5500000/messages")    ' change 9900778 to your BW account ID
            myReq.Method = "POST"
            myReq.ContentType = "application/json"
            myReq.Accept = "application/json"
            myReq.Headers.Add("Authorization", "Basic dXNlcm5hbWU6cGFzc3dvcmQ=") ' username:password encoded in base64' need to set your data here
            Dim myData As String = "{""to"":""+19195551234"",""from"":""+19195551234"",""applicationId"":""9414cd26-720b-43ae-9e45-33f4a3f283f3"", ""text"": ""hello from vb""}"
            myReq.GetRequestStream.Write(System.Text.Encoding.UTF8.GetBytes(myData), 0, System.Text.Encoding.UTF8.GetBytes(myData).Count)
            myResp = myReq.GetResponse
            myReader = New System.IO.StreamReader(myResp.GetResponseStream)
            Console.WriteLine(myReader)
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End SubEnd Module
 
Share this answer
 
Comments
John Pope 2023 11-Oct-23 16:13pm    
I have the following coded like you showed and this is what I am doing to encode the user:password to base64... Is this correct???

Dim strB64Decoded As String = User & ":" & Password
Dim data As Byte() = System.Text.Encoding.UTF8.GetBytes(strB64Decoded)
Dim strB64Encoded As String = Convert.ToBase64String(data)

Appreciate your help... I think I am still much closer, it still closes the request with an error so I think it is my user:password that might not be correct...
Member 16112833 11-Oct-23 16:25pm    
it could be, but id need to know the error.

Did you change the 5500000 in the URL to your accountId? That would cause a 401
John Pope 2023 11-Oct-23 16:30pm    
Yes I did change the 5500000 in the URL to my account ID... The error I am getting back is: "The underlying connection was closed: An unexpected error occurred on a receive."
Member 16112833 11-Oct-23 16:36pm    
> The underlying connection was closed: An unexpected error occurred on a receive.
Something is improper with the request at the network level, it isnt hitting the BW API, otherwise you would get an HTTP response code of some sorts

This may be the issue
https://stackoverflow.com/a/37219622

Depending on your os behavior it may be trying to send with TLS1.0 which Bandwidth does not support, TLS1.2 should work

edit: adding this line inside SendSMS() might be the fix you need

System.Net.ServicePointManager.SecurityProtocol = DirectCast(3072, System.Net.SecurityProtocolType) 'TLS 1.2
John Pope 2023 12-Oct-23 17:40pm    
I think that did the trick, using TLS 1.2 I am getting a 202 Accepted message, don't get the message on the phone but it seems to be working, when I change any of login:password it fails with an authentication message which I would expect... Will work on bandwidth.com to figure out why it's not sending out... Appreciate your help, will let you know when I have more info...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900