0 Replies Latest reply: Aug 1, 2013 5:13 PM by Alejandro Cortada RSS

    VBScript Failure on Macro

    Alejandro Cortada
      Hi All,
      
      We need to pull data from an internal webserivce in our company and was thinking in doing via VBscript macro.
      I need to create various functions for each step, create session, close session, request and manage the response to finalize in a qvd.
      I'm not a programmer and I hardly managed to write the below Sub for the sessioncreate, which is failing as "Syntax error, Macro parse failed", obvioulsy I have
      mistaken somewhere between the first two lines since it is highlighted when fails.
      Any assistance and guidance will be greatly appreciated!
      
      
      Sub SessionCreate
      Namespace com.Company.WebServiceConsumer.Res
             Class SessionCreateRQClient
              ' <summary>
              ' The main entry point.
              ' </summary>
              <STAThread()> _
              Private Shared Sub Main(ByVal args As String())
                  Try
                      ' Set user information, including security credentials and the location.
                      Dim username As String = "user"
                      Dim password As String = "password"
                      Dim ipcc As String = "Location"
                      Dim domain As String = "DEFAULT"
      
                      Dim temp As String = Environment.GetEnvironmentVariable("tmp")
                      ' Get temp directory
                      Dim PropsFileName As String = temp & "/session.properties"
                      ' Define dir and file name
                      Dim dt As DateTime = DateTime.UtcNow
                      Dim tstamp As String = dt.ToString("s") & "Z"
      
                      'Create the message header and provide the conversation ID.
                      Dim msgHeader As New MessageHeader()
                      msgHeader.ConversationId = "TestSession"
                      ' Set the ConversationId
                      Dim from As New From()
                      Dim fromPartyId As New PartyId()
                      Dim fromPartyIdArr As PartyId() = New PartyId(0) {}
                      fromPartyId.Value = "WebServiceClient"
                      fromPartyIdArr(0) = fromPartyId
                      from.PartyId = fromPartyIdArr
                      msgHeader.From = from
      
                      Dim [to] As New [To]()
                      Dim toPartyId As New PartyId()
                      Dim toPartyIdArr As PartyId() = New PartyId(0) {}
                      toPartyId.Value = "WebServiceSupplier"
                      toPartyIdArr(0) = toPartyId
                      [to].PartyId = toPartyIdArr
                      msgHeader.[To] = [to]
      
                      msgHeader.CPAId = Location
                      msgHeader.Action = "SessionCreateRQ"
                      Dim service As New Service()
                      service.Value = "SessionCreate"
                      msgHeader.Service = service
      
                      Dim msgData As New MessageData()
                      msgData.MessageId = "mid:20001209-133003-2333@company.com1"
                      msgData.Timestamp = tstamp
                      msgHeader.MessageData = msgData
      
                      Dim security As New Security()
                      Dim securityUserToken As New SecurityUsernameToken()
                      securityUserToken.Username = username
                      securityUserToken.Password = password
                      securityUserToken.Organization = location
                      securityUserToken.Domain = domain
                      security.UsernameToken = securityUserToken
      
      
                      Dim req As New SessionCreateRQ()
                      Dim pos As New SessionCreateRQPOS()
                      Dim source As New SessionCreateRQPOSSource()
                      source.PseudoCityCode = ipcc
                      pos.Source = source
                      req.POS = pos
      
                      Dim serviceObj As New SessionCreateRQService()
                      serviceObj.MessageHeaderValue = msgHeader
                      serviceObj.SecurityValue = security
      
      
                      Dim resp As SessionCreateRS = serviceObj.SessionCreateRQ(req)
                      ' Send the request
                      If resp.Errors IsNot Nothing AndAlso resp.Errors.[Error] IsNot Nothing Then
                          Console.WriteLine("Error : " + resp.Errors.[Error].ErrorInfo.Message)
                      Else
      
                          msgHeader = serviceObj.MessageHeaderValue
                          security = serviceObj.SecurityValue
      
                          Console.WriteLine("**********************************************")
                          Console.WriteLine("Response of SessionCreateRQ service")
                          Console.WriteLine("BinarySecurityToken returned : " + security.BinarySecurityToken)
                          Console.WriteLine("**********************************************")
                          Dim ConvIdLine As String = "convid=" + msgHeader.ConversationId
                          ' ConversationId to a string
                          Dim TokenLine As String = "securitytoken=" + security.BinarySecurityToken
                          ' BinarySecurityToken to a string
                          Dim ipccLine As String = "Location=" & Location
                          File.Delete(PropsFileName)
                          ' Clean up
                          Dim tw As TextWriter = New StreamWriter(PropsFileName)
                          ' Create & open the file
                          tw.WriteLine(DateTime.Now)
                          ' Write the date for reference
                          tw.WriteLine(TokenLine)
                          ' Write the BinarySecurityToken
                          tw.WriteLine(ConvIdLine)
                          ' Write the ConversationId
                          tw.WriteLine(LocationLine)
      
                          'Console.Read();
                          tw.Close()
      
                      End If
                  Catch e As Exception
                      Console.WriteLine("Exception Message : " & e.Message)
                      Console.WriteLine("Exception Stack Trace : " & e.StackTrace)
                      Console.Read()
                  End Try
      
      
              End Sub
          End Class
      End Namespace
      
      End Sub
      
      
      
      

       

      Thanks Alejo.