CLass
8/4/2004 12:35:00 AM
Hi
I saw your article on dotnet247.com and that is exactly I have done for one of our requirements.
The Requirement is on the event on Button click in the code behind, a class library method gets invoked
which generates the data as per user selection and posts it to the URL.
Below is the code which I am using, this when directly called from the code behind works fine, but when
it is put in the method in the class library, which is called from Code behind fails with the below error
The Remote server returned an error (405) Method not allowed.
What would be the problem? Why do I get the error in the Class Library Method and not in Code Behind.
Is is something to do with the user rights ?
Please Help me out.
Code Sample:-
URL = OCOAApplnHelper.AppSetting.GetTEWSURL
userId = OCOAApplnHelper.AppSetting.GetTEWSUserId
password = OCOAApplnHelper.AppSetting.GetTEWSPassword
startTime = Now.ToShortDateString & " - " & Now.ToLongTimeString
'POST THE XML FILE TO THE URL
Request = DirectCast(WebRequest.Create(URL), HttpWebRequest)
Request.Method = "POST"
Request.ContentLength = outXML.Length
Request.ContentType = "text/xml"
Dim myCred As New NetworkCredential(userId, password )
Request.Credentials = myCred
mywriter = New StreamWriter(Request.GetRequestStream())
mywriter.Write(outXML)
mywriter.Flush()
mywriter.Close()
'READ THE RESPONSE FROM THE URL
Response = DirectCast(Request.GetResponse(), HttpWebResponse)
If Response.StatusCode = HttpStatusCode.OK Then
myReader = New StreamReader(Response.GetResponseStream())
returnXML = myReader.ReadToEnd
Return 0
Else
Return 99
Throw New OCOAExpHelper.FWUtilityException("TEWSInterfaceBC.postXMLToURL Falied: " & Response.StatusCode)
End If
myCred = Nothing
Catch Webex As WebException
Throw New OCOAExpHelper.FWUtilityException("TEWSInterfaceBC.PostXMLToURL: " & Webex.Message, Webex)
Catch ex As System.Exception
Throw New OCOAExpHelper.FWUtilityException("TEWSInterfaceBC.PostXMLToURL: " & ex.Message, ex)
Finally
mywriter = Nothing
myReader = Nothing
Request = Nothing
Response = Nothing
End Try