I am calling a web service below and translated the code from C# but have one item I can't resolve. In the Catch soapException I have a line that says, "Name 'Utilities' is not declared". Anyone know how I declare it? If I comment out that section the code works fine but probably a good idea to include this.
related codeCode:Public Overrides Function RetrieveDocument( _ ByVal pNumber As String, _ ByVal PDate As String, _ ByVal DownloadPath As String) As Boolean Dim bReturn As Boolean bReturn = False Dim imagingService As DflImagingService.ImagingService = Nothing Dim results As DflImagingService.ImageResult() = Nothing Dim credentials As DflImagingService.Credentials = Nothing Dim fileStream As fileStream = Nothing Dim pro As Long = 0 pro = CType(pNumber, Long) Dim ctr As Integer = 0 Try ' Instantiate the web service objects. imagingService = New DflImagingService.ImagingService() credentials = New DflImagingService.Credentials() ' Set username/password properties of credentials object. credentials.UserName = m_sUsername credentials.Password = m_sPassword ' Set the credentials property of the imaging service to your credentials object. imagingService.CredentialsValue = credentials ' Call the TrackByDate() web method. results = imagingService.GetImages(pro) Dim result As DflImagingService.ImageResult For Each result In results If result.Exceptions Is Nothing Then If result.DocumentType = "DELIVERY RECEIPT" Then ' Do something w/ image data. fileStream = New fileStream(DownloadPath, FileMode.Create) fileStream.Write(result.ImageData, 0, result.ImageData.Length) fileStream.Seek(0, SeekOrigin.Begin) fileStream.Close() bReturn = True End If Else Dim i As Integer For i = 0 To result.Exceptions.Length - 1 Log2File("error: " & result.Exceptions(i)) Next End If ctr += 1 Next Catch soapException As System.Web.Services.Protocols.SoapException '******** ERROR: Name 'Utilities' is not declared ********* Dim webServiceExceptions As WebServiceException() = Utilities.ParseSoapException(soapException) Dim stringBuilder As New stringBuilder() Dim i As Integer For i = 0 To webServiceExceptions.Length - 1 stringBuilder.Append(webServiceExceptions(i).Message & vbCr & vbLf) Next Throw New Exception(stringBuilder.ToString()) Finally If Not (imagingService Is Nothing) Then imagingService.Dispose() End If imagingService = Nothing credentials = Nothing If Not (fileStream Is Nothing) Then fileStream.Close() End If fileStream = Nothing End Try Return bReturn End Function
Code:Public Class WebServiceException Inherits System.ApplicationException Private m_number As Integer Public Property Number() As Integer Get Return Me.m_number End Get Set(ByVal value As Integer) Me.m_number = value End Set End Property Private m_type As String Public Property Type() As String Get Return Me.m_type End Get Set(ByVal value As String) Me.m_type = value End Set End Property Private m_message As String Public Shadows Property Message() As String Get Return Me.m_message End Get Set(ByVal value As String) Me.m_message = value End Set End Property Public Sub New() End Sub Public Sub New(ByVal number As Integer, ByVal type As String, ByVal message As String) Me.m_number = number Me.m_type = type Me.m_message = message End Sub Public Shared Function ParseSoapException(ByVal soapException As System.Web.Services.Protocols.SoapException) As WebServiceException() Dim exceptions As WebServiceException() Dim i As Integer Try exceptions = New WebServiceException(soapException.Detail.ChildNodes.Count - 1) {} For i = 0 To exceptions.Length - 1 exceptions(i) = New WebServiceException(Convert.ToInt32(soapException.Detail.ChildNodes(i).Attributes("e:number").Value), soapException.Detail.ChildNodes(i).Attributes("e:type").Value, soapException.Detail.ChildNodes(i).Attributes("e:message").Value) Return exceptions Next Catch exception As exception Throw exception Finally exceptions = Nothing End Try End FunctionCode:' imports using Imports System Imports System.IO Imports System.Net Imports System.Text.RegularExpressions Imports DflImagingService 'web service Imports System.Web.Services.Protocols.SoapMessage Imports System.Web.Services.Protocols.SoapException Imports System.Text Imports System.Web




Reply With Quote