VB API

  • Thread starter Thread starter old_School
  • Start date Start date
O

old_School

Guest
I have never made a API in vb only in C3 using the project preset up as an api project. Here is the code I have given to me. I have never worked with IHttpHandler before so I'm not even sure how to handle routing etc.


Imports System.Web
Imports System.Web.Services
Imports Collage.Helpers.Components
Imports Collage.Business
Imports Newtonsoft.Json

Namespace api
Public Class change
Implements System.Web.IHttpHandler

Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim oChangeOrder As ChangeOrder, oResponse As Domain.Structures.Structures.ReturnResponse
Dim Input_sr As StreamReader
Dim sData As String
Dim sReturn As String

Try
Input_sr = New StreamReader(context.Request.InputStream)
sData = Input_sr.ReadToEnd
Input_sr.Close()

If context.Request.ContentType.StartsWith("application/xml") Then
oChangeOrder = New ChangeOrder(sData, False)
oResponse = oChangeOrder.Process
context.Response.StatusCode = HttpStatusCode.OK

If oResponse.ReturnCode = "Error" Then
sReturn = String.Format(Utils._sOrderErrorXML, oResponse.Message, oResponse.Message)
Else
sReturn = String.Format(Utils._sOrderOkXML, oResponse.Message)
End If
Else
sReturn = String.Format(Utils._sOrderErrorXML, "Error", "Invalid content type")
End If
Catch ex As Exception
context.Response.StatusCode = HttpStatusCode.BadRequest
Utils.ErrorEmail("Change Error!", ex, AttachmentName:="Change.xml", AttachmentData:=sData)
sReturn = String.Format(Utils._sOrderErrorXML, "Error", ex.Message)
End Try

context.Response.ContentType = "application/xml"
context.Response.Write(sReturn)
End Sub


ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property

End Class
End Namespace


I have no idea what this is or how to work with it. Anyone have any information about this and how to route it etc?

Continue reading...
 
Back
Top