I'm currently trying to build a component I can use in traditional ASP
that utilizes the .NET webservice. I'm using VB.NET to create my class,
and I am registering the class for COM Interop when I compile. I'm
encountering some problems with testing using the class in a VB.NET
console application. I keep getting a http 405 error (I've never seen
this kind of error before).
In Visual Studio, I get this error:
An unhandled exception of type 'System.Net.WebException' occurred in
system.web.services.dll
Additional information: The request failed with HTTP status 405: Method
Not Allowed.
Here is the source code for the class I'm using:
Expand|Select|Wrap|Line Numbers
- Public Class Proximity
- Private _strPublicStagingURL As String
- Private _strPublicProductionURL As String
- Private _strSecureStagingURL As String
- Private _strSecureProductionURL As String
- Private _strStreet As String
- Private _strCity As String
- Private _strState As String
- Private _strZip As String
- Private _strCountry As String
- Private _dblFoundLatitude As Double
- Private _dblFoundLongitude As Double
- Private _boolFoundLocation As Boolean
- Private _envType As envEnvironment
- Private _strUsername As String
- Private _strPassword As String
- Private _strDataSourceName As String
- Private _intNumberFound As Integer
- Private _strErrorMessage As String
- Private _strReturnedFormattedAddress As String
- Public Sub New()
- _strPublicStagingURL =
- "http://staging.mappoint.net/standard-30/mappoint.wsdl"
- _strPublicProductionURL =
- "http://service.mappoint.net/standard-30/mappoint.wsdl"
- _strSecureStagingURL =
- "https://staging.mappoint.net/secure-30/mappoint.wsdl"
- _strSecureProductionURL =
- "https://service.mappoint.net/secure-30/mappoint.wsdl"
- _strStreet = Nothing
- _strCity = Nothing
- _strState = Nothing
- _strZip = Nothing
- _strCountry = "US"
- _dblFoundLatitude = Nothing
- _dblFoundLongitude = Nothing
- _boolFoundLocation = False
- _envType = envEnvironment.envPublicStaging
- _strUsername = Nothing
- _strPassword = Nothing
- _strDataSourceName = "MapPoint.NA"
- _intNumberFound = Nothing
- _strErrorMessage = Nothing
- _strReturnedFormattedAddress = Nothing
- End Sub
- Public Enum envEnvironment As Integer
- envPublicStaging = 1
- envPublicProduction = 2
- envSecureStaging = 3
- envSecureProduction = 4
- End Enum
- Public Property Username() As String
- Get
- Return _strUsername
- End Get
- Set(ByVal Value As String)
- _strUsername = Value
- End Set
- End Property
- Public Property Password() As String
- Get
- Return _strPassword
- End Get
- Set(ByVal Value As String)
- _strPassword = Value
- End Set
- End Property
- Public Property ProcessingType() As envEnvironment
- Get
- Return _envType
- End Get
- Set(ByVal Value As envEnvironment)
- _envType = Value
- End Set
- End Property
- Public Property PublicStagingURL() As String
- Get
- Return _strPublicStagingURL
- End Get
- Set(ByVal Value As String)
- _strPublicStagingURL = Value
- End Set
- End Property
- Public Property PublicProductionURL() As String
- Get
- Return _strPublicProductionURL
- End Get
- Set(ByVal Value As String)
- _strPublicProductionURL = Value
- End Set
- End Property
- Public Property SecureProductionURL() As String
- Get
- Return _strSecureProductionURL
- End Get
- Set(ByVal Value As String)
- _strSecureProductionURL = Value
- End Set
- End Property
- Public Property SecureStagingURL() As String
- Get
- Return _strSecureStagingURL
- End Get
- Set(ByVal Value As String)
- _strSecureStagingURL = Value
- End Set
- End Property
- Public Property Street() As String
- Get
- Return _strStreet
- End Get
- Set(ByVal Value As String)
- _strStreet = Value
- End Set
- End Property
- Public Property City() As String
- Get
- Return _strCity
- End Get
- Set(ByVal Value As String)
- _strCity = Value
- End Set
- End Property
- Public Property State() As String
- Get
- Return _strState
- End Get
- Set(ByVal Value As String)
- _strState = Value
- End Set
- End Property
- Public Property Zip() As String
- Get
- Return _strZip
- End Get
- Set(ByVal Value As String)
- _strZip = Value
- End Set
- End Property
- Public Property Country() As String
- Get
- Return _strCity
- End Get
- Set(ByVal Value As String)
- _strCity = Value
- End Set
- End Property
- Public ReadOnly Property LastError() As String
- Get
- Return _strErrorMessage
- End Get
- End Property
- Public ReadOnly Property HasError() As Boolean
- Get
- Return _strErrorMessage = ""
- End Get
- End Property
- Public ReadOnly Property ReturnedAddress() As String
- Get
- Return _strReturnedFormattedAddress
- End Get
- End Property
- Public ReadOnly Property FoundLocation() As Boolean
- Get
- Return _boolFoundLocation
- End Get
- End Property
- Public ReadOnly Property FoundLatitude() As Double
- Get
- Return _dblFoundLatitude
- End Get
- End Property
- Public ReadOnly Property FoundLongitude() As Double
- Get
- Return _dblFoundLongitude
- End Get
- End Property
- Public Sub FindAddress()
- 'Set up the Address object and the FindAddressSpecification
- object
- Dim findService As New MapPoint.FindServiceSoap
- Dim myAddress As New MapPoint.Address
- Dim sstrURL As String
- Dim foundAddressResults As MapPoint.FindResults
- Dim findAddressSpec As New MapPoint.FindAddressSpecification
- findService.Credentials = New
- System.Net.NetworkCredential(_strUsername, _strPassword)
- Select Case _envType
- Case envEnvironment.envPublicStaging
- sstrURL = _strPublicStagingURL
- Case envEnvironment.envPublicProduction
- sstrURL = _strPublicProductionURL
- Case envEnvironment.envSecureProduction
- sstrURL = _strSecureProductionURL
- Case envEnvironment.envSecureStaging
- sstrURL = _strSecureStagingURL
- Case Else
- sstrURL =
- "http://staging.mappoint.net/standard-30/MapPoint.wsdl"
- End Select
- If _strDataSourceName <> "" Then
- findAddressSpec.DataSourceName = _strDataSourceName
- Else
- findAddressSpec.DataSourceName = "MapPoint.NA"
- End If
- If _strStreet <> "" Then
- myAddress.AddressLine = _strStreet
- End If
- If _strCity <> "" Then
- myAddress.PrimaryCity = _strCity
- End If
- If _strState <> "" Then
- myAddress.Subdivision = _strState
- End If
- If _strZip <> "" Then
- myAddress.PostalCode = _strZip
- End If
- If _strCountry <> "" Then
- myAddress.CountryRegion = _strCountry
- Else
- myAddress.CountryRegion = "US"
- End If
- findAddressSpec.InputAddress = myAddress
- findService.Url = sstrURL
- 'Try
- foundAddressResults = findService.FindAddress(findAddressSpec)
- _intNumberFound = foundAddressResults.NumberFound
- If IsNothing(_intNumberFound) Then
- _boolFoundLocation = False
- _dblFoundLatitude = Nothing
- _dblFoundLongitude = Nothing
- _strReturnedFormattedAddress = Nothing
- ElseIf _intNumberFound = 0 Then
- _dblFoundLatitude = Nothing
- _dblFoundLongitude = Nothing
- _strReturnedFormattedAddress = Nothing
- _boolFoundLocation = False
- ElseIf _intNumberFound = 1 Then
- _boolFoundLocation = True
- _dblFoundLatitude =
- foundAddressResults.Results(0).FoundLocation.LatLong.Latitude
- _dblFoundLongitude =
- foundAddressResults.Results(0).FoundLocation.LatLong.Longitude
- _strReturnedFormattedAddress =
- foundAddressResults.Results(0).FoundLocation.Address.FormattedAddress
- Else
- _boolFoundLocation = False
- _dblFoundLatitude = Nothing
- _dblFoundLongitude = Nothing
- _strReturnedFormattedAddress = Nothing
- End If
- 'Catch ex As Exception
- ' _strErrorMessage = ex.GetBaseException.ToString
- ' _dblFoundLatitude = Nothing
- ' _dblFoundLongitude = Nothing
- ' _strReturnedFormattedAddress = Nothing
- 'End Try
- End Sub
- End Class
- Here is the call I'm using in my console application to make this happen:
- Sub Main()
- Dim objPS As New Proximity
- Console.WriteLine("Press ENTER to continue...")
- Console.ReadLine()
- objPS.Username = "xxxxx"
- objPS.Password = "xxxxxx"
- objPS.ProcessingType = Proximity.envEnvironment.envPublicStaging
- objPS.State = "FL"
- objPS.City = "Miami Lakes"
- objPS.Zip = "33014"
- objPS.FindAddress()
- If objPS.FoundLocation Then
- Console.WriteLine("Lat: " & objPS.FoundLatitude.ToString &
- " Long: " & objPS.FoundLongitude.ToString)
- Else
- Console.WriteLine("no geocode returned")
- If objPS.HasError Then
- Console.WriteLine(objPS.LastError)
- End If
- End If
- Console.WriteLine("Press ENTER to exit...")
- Console.ReadLine()
- End Sub
the error occurs when the "foundAddressResults =
findService.FindAddress(findAddressSpec)" line fires in the class.
The interesting thing is, I've had this search code work before... I
don't know what I should be looking for or doing to solve my current
problem. :(
TIA,
Cory Koski