[Mono-list] Executing ASP.net page out side IIS (in apache)
rmahato@dacafe.com
rmahato@dacafe.com
Tue, 26 Mar 2002 07:40:24 -0800
hi
i am working on developing a ISAPI application for executing a asp.net
page in a apache application
i would like to contibute in the areas for developing asp.net runtime..
any idea where i can start on.
Raj
==========
regarding what i am doing :
1) and ISAP dll for ruting .aspx/asmx request in apache
2) process this request in .net framework
using system.web.hosting.applicationshost
httpworkerrequest.
i am able to execute the code form am exe
but whe i call the dotnet component form an ISAPI applicatio it throws
and exception
The type initializer for "System.Web.HttpRuntime" threw an exception.
=================
.net componet code
==================
using System;
using System.Web;
using System.IO ;
using System.Web.Hosting;
using System.Runtime.InteropServices ;
namespace ASPNET
{
/// <summary>
/// Summary description for Class1.
/// </summary>
///
public class MyExeHost : MarshalByRefObject
{
public void ProcessRequest(string page,ref string Output)
{
try
{
MemoryStream ms= new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
//BinaryWriter bw = new BinaryWriter(ms);
//HttpContext hc= HttpContext.Current;
sw.AutoFlush = true;
HttpRuntime.ProcessRequest(new SimpleWorkerRequest(page ,null,sw));
StreamReader sr= new StreamReader(ms);
ms.Position =0;
Output = sr.ReadToEnd();
}
catch(Exception ex)
{
Output = ex.Message+page;
return;
}
}
}
public interface IMyHost
{
void ExecutePage(string page,string AppName, string AppDir, ref
string Output);
}
[ClassInterface(ClassInterfaceType.None )]
public class MyHost :IMyHost
{
public void ExecutePage(string page,string AppName, string AppDir,
ref string Output)
{
try
{
MyExeHost host =
(MyExeHost)ApplicationHost.CreateApplicationHost(typeof(MyExeHost),
AppName,AppDir);
host.ProcessRequest(page, ref Output);
}
catch(Exception ex)
{
Output = ex.Message +page+" Execute page "+AppName+AppDir;
}
}
}
}
====================
ISAPI code
======================
// validate.cpp : Defines the entry point for the DLL application.
//
#include <windows.h>
//#include "compnet.h"
#include "httpext.h"
#include "stdio.h"
#import "aspnetcomp.tlb"
void WriteContext(EXTENSION_CONTROL_BLOCK *pECB, char *pszFormat, ...);
int ExecPage(BSTR pg ,BSTR ap ,BSTR dr ,BSTR *out) ;
//DLL Entry point
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID
lpReserved)
{
return TRUE;
}
//Ist Function called by IIS
BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer)
{
pVer->dwExtensionVersion = HSE_VERSION;
strncpy(pVer->lpszExtensionDesc, "Validate ISAPI Extension",
HSE_MAX_EXT_DLL_NAME_LEN);
return TRUE;
}
//start
void StartContext(EXTENSION_CONTROL_BLOCK *pECB)
{
WriteContext(pECB, "<html>\r\n<body>\r\n");
}
//end
void EndContext(EXTENSION_CONTROL_BLOCK *pECB)
{
WriteContext(pECB, "</body>\r\n</html>");
}
//for Writing Data back to client
void WriteContext(EXTENSION_CONTROL_BLOCK *pECB, char *pszFormat, ...)
{
char szBuffer[1024];
va_list arg_ptr;
va_start(arg_ptr, pszFormat);
vsprintf(szBuffer, pszFormat, arg_ptr);
va_end(arg_ptr);
DWORD dwSize = strlen(szBuffer);
pECB->WriteClient(pECB->ConnID, szBuffer, &dwSize, 0);
}
//Function called for processing the client Request
DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB)
{
StartContext(pECB);
WriteContext(pECB, "<p><b><font face='Verdana' color='#008000'>This
Message is recieved form ISAPI application!</font></b></p>");
WriteContext(pECB, pECB->lpszQueryString);
WriteContext(pECB, "<HR>");
LPSTR tt= "test.aspx" ;
BSTR pp= (wchar_t *)malloc( sizeof( wchar_t ));
int ss= mbstowcs( pp, tt, strlen(tt)+1);
BSTR pg = ::SysAllocString(pp);
BSTR out =::SysAllocString( L"Invalid output" );
WriteContext(pECB, "<HR>");
// int rc = ExecPage (L"test.aspx",L"/myapp",L"E:\\raj\\mypages",
&out);
unsigned int sz = ::SysStringLen (out) ;
char *result = new char [2*sz+1] ;
wcstombs(result,out, sz+1);
WriteContext(pECB,result);
WriteContext(pECB, "<HR>");
EndContext(pECB);
return HSE_STATUS_SUCCESS;
}
//
BOOL WINAPI TerminateExtension(DWORD dwFlags)
{
//dwFlags=HSE_TERM_MUST_UNLOAD ;
return TRUE;
}
///////////////////////////////
int ExecPage(BSTR pg ,BSTR ap ,BSTR dr ,BSTR *out)
{
using namespace ASPNETComp;
HRESULT hr;
int Rc =-1;
IMyCompHost *hstPtr;
CoInitialize(NULL);
hr = CoCreateInstance ( __uuidof(MyComHost), // CLSID of coclass
NULL, // not used -
aggregation
CLSCTX_INPROC_SERVER, // type of server
__uuidof (IMyCompHost), // IID of
interface
(void**) &hstPtr); // Pointer to our
interface pointer
if ( SUCCEEDED ( hr ) )
{
// Call methods using pISL here.
//printf(" \nSuccess in Creating the COM Class");
// Long see variant table for codes
BSTR page= ::SysAllocString (pg);
BSTR app =::SysAllocString(ap);
BSTR dir = ::SysAllocString(dr);
//BSTR output = :: SysAllocString( out );
hr=hstPtr->ExecutePage(page,app,dir,out);
if ( SUCCEEDED ( hr ) )
{
//printf("Success in calling the method");
unsigned int sz = ::SysStringLen (*out) ;
char *result = new char [sz] ;
wcstombs(result,*out, sz);
// printf("\nResult :\n\n%s",result);
Rc=0;
}
else
{
//printf("Failed in calling the method");
Rc=-1;
}
hstPtr->Release();
}
else
{
// Couldn't create the COM object. hr holds the error code.
//printf(" \nError in Creating The COM Object:");
Rc=-1;
}
//Unload comobject
CoUninitialize();
return Rc;
}
/*
int ExecPage(BSTR pg ,BSTR ap ,BSTR dr ,BSTR *out)
{
using namespace ASPNET;
HRESULT hr;
int Rc =-1;
IMyHost *hstPtr;
CoInitialize(NULL);
hr = CoCreateInstance ( __uuidof(MyHost), // CLSID of coclass
NULL, // not used -
aggregation
CLSCTX_INPROC_SERVER, // type of server
__uuidof (IMyHost), // IID of
interface
(void**) &hstPtr); // Pointer to our
interface pointer
if ( SUCCEEDED ( hr ) )
{
// Call methods using pISL here.
//printf(" \nSuccess in Creating the COM Class");
// Long see variant table for codes
BSTR page= ::SysAllocString (pg);
BSTR app =::SysAllocString(ap);
BSTR dir = ::SysAllocString(dr);
//BSTR output = :: SysAllocString( out );
hr=hstPtr->ExecutePage(page,app,dir,out);
if ( SUCCEEDED ( hr ) )
{
//printf("Success in calling the method");
unsigned int sz = ::SysStringLen (*out) ;
char *result = new char [sz] ;
wcstombs(result,*out, sz);
// printf("\nResult :\n\n%s",result);
Rc=0;
}
else
{
//printf("Failed in calling the method");
Rc=-1;
}
hstPtr->Release();
}
else
{
// Couldn't create the COM object. hr holds the error code.
//printf(" \nError in Creating The COM Object:");
Rc=-1;
}
//Unload comobject
CoUninitialize();
return Rc;
}*/
//////////comp header
// Created by Microsoft (R) C/C++ Compiler Version 12.00.8168.0
(fbe69483).
//
// \\inatpdqml21s\genhfrom tlb\compnet\debug\aspnet.tlh
//
// C++ source equivalent of Win32 type library aspnet.tlb
// compiler-generated file created 03/25/02 at 10:38:40 - DO NOT EDIT!
#pragma once
#pragma pack(push, 8)
#include <comdef.h>
namespace ASPNET {
//
// Forward references and typedefs
//
struct /* coclass */ MyExeHost;
struct __declspec(uuid("e24d8042-d758-3c0c-9a8c-bbcd6f2b6ba1"))
/* dual interface */ IMyHost;
struct /* coclass */ MyHost;
struct __declspec(uuid("d7f66457-3a60-3ccb-9f50-12267f756f07"))
/* dual interface */ _MyExeHost;
//
// Smart pointer typedef declarations
//
_COM_SMARTPTR_TYPEDEF(IMyHost, __uuidof(IMyHost));
_COM_SMARTPTR_TYPEDEF(_MyExeHost, __uuidof(_MyExeHost));
//
// Type library items
//
struct __declspec(uuid("c42ca746-c369-378c-98d6-d800eeb88d10"))
MyExeHost;
// [ default ] interface _MyExeHost
// interface _Object
struct __declspec(uuid("e24d8042-d758-3c0c-9a8c-bbcd6f2b6ba1"))
IMyHost : IDispatch
{
//
// Wrapper methods for error-handling
//
HRESULT ExecutePage (
_bstr_t page,
_bstr_t AppName,
_bstr_t AppDir,
BSTR * Output );
//
// Raw methods provided by interface
//
virtual HRESULT __stdcall raw_ExecutePage (
BSTR page,
BSTR AppName,
BSTR AppDir,
BSTR * Output ) = 0;
};
struct __declspec(uuid("5543e24c-9d66-39b0-8507-73a5357e77ba"))
MyHost;
// interface _Object
// [ default ] interface IMyHost
struct __declspec(uuid("d7f66457-3a60-3ccb-9f50-12267f756f07"))
_MyExeHost : IDispatch
{};
//
// Wrapper method implementations
//
//#include "\\inatpdqml21s\genhfrom tlb\compnet\debug\aspnet.tli"
inline HRESULT IMyHost::ExecutePage ( _bstr_t page, _bstr_t AppName,
_bstr_t AppDir, BSTR * Output ) {
HRESULT _hr = raw_ExecutePage(page, AppName, AppDir, Output);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _hr;
}
} // namespace ASPNET
#pragma pack(pop)
//////////////////
///////
Any help in this regard ll be great
Raj
_____________________________________________________________