C # - web service with aspx page

We must use a specific library for serialization, which is used as follows:

var obj = Serializer.Deserialize(myStream); //Read
Serializer.Serialize(obj, myOtherStream); //Write

We need to expose this via the web service, and I got this work as such:

  • File → New Project → ASP.Net WebForms Website
  • In Page.Load, we use the Request and Response elements to serialize.
  • Change ContentType in response
  • Then we call Response.End ()
  • We also needed to put Async = "true" on the aspx page

And all this seems to be working fine.

Is there a better way to handle this? We want our service to run in IIS, but we did not know if there was an overhead for creating this aspx page.

Is there any use for connecting to WCF?

+3
source share
1

, , -, . .

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {

        context.Response.ContentType = "text/xml";
        Serializer.Serialize(obj, context.Response.Stream); //Write

    }

    public bool IsReusable {
        get {
            return false;
        }
    }
}
+6

Source: https://habr.com/ru/post/1795508/


All Articles