Sub SendVoiceMessage_WAV() 'Send a WAV file Base64 encoded in a JobSubmitRequest XML file Dim XOA As EMsgAPIJobSubmit200907.XOA = New EMsgAPIJobSubmit200907.XOA Dim request As EMsgAPIJobSubmit200907.Request = New EMsgAPIJobSubmit200907.Request Dim authentication As EMsgAPIJobSubmit200907.Authentication = New EMsgAPIJobSubmit200907.Authentication Dim xddsauth As EMsgAPIJobSubmit200907.XDDSAuthType = New EMsgAPIJobSubmit200907.XDDSAuthType Dim jobrequest As EMsgAPIJobSubmit200907.JobSubmitRequest = New EMsgAPIJobSubmit200907.JobSubmitRequest XOA.Url = GetRequestUrl() request.ReceiverKey = GetRequestUrl() 'This returns the URL of PGiConnect Server API_Demo.txtResult.Text = "Please wait..." Application.DoEvents() jobrequest.SubmitId = "Voice Message Test" ' WebProxy traps the XML request and response files. If API_Demo.chkUseProxyTrace.Checked Then XOA.Proxy = New System.Net.WebProxy("http://localhost:8080") End If ' Build the SOAP Header xddsauth.RequesterID = API_Demo.txtUserID.Text 'UID xddsauth.Password = API_Demo.txtPassword.Text 'Password authentication.XDDSAuth = xddsauth request.Authentication = authentication request.ReceiverKey = GetRequestUrl() request.ResultRequired = EMsgAPIJobSubmit200907.RequiredType.yes request.RequestID = "Test" XOA.RequestValue = request 'Documents Dim document As EMsgAPIJobSubmit200907.DocumentType() Dim documentdata As EMsgAPIJobSubmit200907.DocDataType = New EMsgAPIJobSubmit200907.DocDataType documentdata.format = EMsgAPIJobSubmit200907.DocEncodingFormat.base64 ReDim document(1) ' PDF Message Dim inFile As System.IO.FileStream Dim binaryData() As Byte Dim bytesRead As Long Try inFile = New System.IO.FileStream("C:\Work\TestFiles\WAV\message.wav", IO.FileMode.Open, IO.FileAccess.Read) ReDim binaryData(CInt(inFile.Length)) bytesRead = inFile.Read(binaryData, 0, CInt(inFile.Length)) inFile.Close() Catch exp As System.Exception ' Error creating stream or reading from it. MsgBox("Error: {0}", exp.Message) Return End Try 'convert WAV binary into Base64 UUEncoded output: Dim base64String As String Try 'base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length) base64String = System.Convert.ToBase64String(binaryData, 0, bytesRead) Catch ex As Exception MsgBox("Error Converting Base64 :" & ex.Message) Return End Try documentdata = New EMsgAPIJobSubmit200907.DocDataType documentdata.format = EMsgAPIJobSubmit200907.DocEncodingFormat.base64 documentdata.Value = base64String document(0) = New EMsgAPIJobSubmit200907.DocumentType document(0).DocType = "WAV" document(0).ref = "DocOne" Dim myFileName As EMsgAPIJobSubmit200907.EncodableStringType = New EMsgAPIJobSubmit200907.EncodableStringType myFileName.Value = "test.wav" document(0).Filename = myFileName 'document(0).ItemElementName = EMsgAPIJobSubmit200907.ItemChoiceType1.DocData document(0).ItemElementName = EMsgAPIJobSubmit200907.ItemChoiceType.DocData document(0).Item = documentdata documentdata = Nothing 'add the documents to the job request jobrequest.DocumentSet = document ' Build a message Dim message As EMsgAPIJobSubmit200907.MessageType() ReDim message(1) message(0) = New EMsgAPIJobSubmit200907.MessageType ' Contents Dim content() As EMsgAPIJobSubmit200907.ContentPartType ReDim content(1) content(0) = New EMsgAPIJobSubmit200907.ContentPartType content(0).Item = "DocOne" content(0).Treatment = EMsgAPIJobSubmit200907.TreatmentType.body 'content(0).Treatment = EMsgAPIJobSubmit200907.TreatmentType.voice_all content(0).TreatmentSpecified = True ' Add the contents to the message message(0).Contents = content ' Setup job options Dim joboptions As EMsgAPIJobSubmit200907.JobOptionsType = New EMsgAPIJobSubmit200907.JobOptionsType() joboptions.CustomerReference = New EMsgAPIJobSubmit200907.EncodableStringType joboptions.CustomerReference.Value = "My Customer Reference" joboptions.BillingCode = New EMsgAPIJobSubmit200907.EncodableStringType joboptions.BillingCode.Value = "My Billing Code" 'setup domain Dim myDomain As String myDomain = "" myDomain = GetDomain() If (myDomain <> "") And (API_Demo.chkDomain.Checked) Then joboptions.Domain = myDomain End If 'setup voice options Dim voiceOptions As EMsgAPIJobSubmit200907.VoiceOptionsType = New EMsgAPIJobSubmit200907.VoiceOptionsType voiceOptions.VoiceDeliveryMethod = EMsgAPIJobSubmit200907.VoiceDeliveryMethodType.PAMD voiceOptions.VoiceDeliveryMethodSpecified = True ' Add the Voice options to the job options joboptions.VoiceOptions = voiceOptions ' Add the job options to the message message(0).JobOptions = joboptions ' Setup reports Dim reports As EMsgAPIJobSubmit200907.ReportOptionsType = New EMsgAPIJobSubmit200907.ReportOptionsType Dim deliveryreport As EMsgAPIJobSubmit200907.ReportOptionsTypeDeliveryReport = New EMsgAPIJobSubmit200907.ReportOptionsTypeDeliveryReport deliveryreport.DeliveryReportType = EMsgAPIJobSubmit200907.MainReportTypeEnum.detail reports.DeliveryReport = deliveryreport ' Add reports to the message message(0).Reports = reports ' Setup delivery destination(s) Dim VoiceNumber As String Dim deliveryVoice() As EMsgAPIJobSubmit200907.VoiceType ReDim deliveryVoice(1) deliveryVoice(0) = New EMsgAPIJobSubmit200907.VoiceType VoiceNumber = API_Demo.txtEmail.Text deliveryVoice(0).Phone = VoiceNumber message(0).Destinations = deliveryVoice jobrequest.Message = message Dim response As EMsgAPIJobSubmit200907.Response = New EMsgAPIJobSubmit200907.Response XOA.ResponseValue = response ' Submit the job request Dim jobresult As EMsgAPIJobSubmit200907.JobSubmitResult = New EMsgAPIJobSubmit200907.JobSubmitResult Try jobresult = XOA.JobSubmit(jobrequest) Catch ex As Exception System.Console.WriteLine("Error: {0}", ex.Message) MsgBox("Error: " & ex.Message) Return End Try 'Process the response ProcessResponse(XOA.ResponseValue) Dim sJobNumber As String If jobresult.Status.StatusCode = 0 Then 'case no error Try sJobNumber = jobresult.MessageResult(0).JobId.XDN & ":" & jobresult.MessageResult(0).JobId.MRN Catch ex As Exception MsgBox("Error reading JobID:" & ex.Message) Return End Try API_Demo.txtResult.Text = ("Job Number=" & sJobNumber & vbCrLf & "Result=" & jobresult.Status.StatusCode & vbCrLf & jobresult.Status.StatusMessage) Else API_Demo.txtResult.Text = ("Result=" & jobresult.Status.StatusCode & vbCrLf & jobresult.Status.StatusMessage) End If End Sub