all groups > dotnet web services > july 2004 >
You're in the

dotnet web services

group:

HTTP 405 Error... help!


HTTP 405 Error... help! Cory Koski
7/29/2004 4:22:24 PM
dotnet web services: Hi all,

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:

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()

Re: HTTP 405 Error... help! Derek Harmon
7/30/2004 9:59:25 PM
[quoted text, click to view]

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6

: :
[quoted text, click to view]

The "method" the error refers to is an HTTP verb (i.e., GET, POST, et al.),
the server's HttpRuntime has been configured not to answer requests with
the HTTP verb specified in your WebRequest (frequently, a GET request).

If you go into the machine.config file, by default you see a line similar to the
following under the <httpHandlers> section of <system.web>:

<add verb="*" path="*.asmx"
type="System.Web.Services.Protocols.WebServiceHandlerFactory, [...]" />

Many server administrators will restrict the verbs their .asmx's respond to:

<add verb="POST" path="*.asmx"
type="System.Web.Services.Protocols.WebServiceHandlerFactory, [...]" />

This change causes a 405 to be returned as the result code for all non-POST
HTTP requests (this reduces the risk of query string buffer overruns, exploits,
etc. on production servers, also due to URL-encoding of the query string, a
GET request isn't terribly practical for most web services, anyway).

[quoted text, click to view]

Assuming findService is your proxy, make sure it derives from
HttpPostClientProtocol and includes an HttpMethodAttribute on
FindAddress( ) similar to the following,

<System.Web.Services.Protocols.HttpMethodAttribute( _
GetType( System.Web.Services.Protocols.XmlReturnReader), _
GetType( System.Web.Services.Protocols.HtmlFormParameterWriter))>

to ensure that your HTTP method is really POST (and not GET). See
the .NET Framework documentation on both of these for all the details.

[quoted text, click to view]

Per RFC 2616 above, the HTTP response you're receiving is supposed
to include an Allow HTTP header. This will probably tell you the server is
only accepting POST, or some limited number of verbs.


HTH,

Derek Harmon

AddThis Social Bookmark Button