 |
 | In IIS7 evolvement | 6:33 17 Mar '09 |
|
 |
Great post, I register the class in IIS6 like your post, IIS6 no any problem, but IIS7 not work. Please help me.
Thanks.
|
|
|
|
 |
 | ASP.NET AJAX eeyrcr | 7:44 20 Jan '09 |
|
 |
Hi,
Great post - but did you ever get it working with ASP.NET AJAX?
I really would love to get this working in my project - any updates / pointers?
Thanks, - Chris
|
|
|
|
 |
 | Re: ASP.NET AJAX Bruno Piovan | 10:26 3 Mar '09 |
|
 |
Hi Chris, please, have a look at the posts with title "Can we use it in ASP .NET AJAX ?"
thanks!
|
|
|
|
 |
 | Why the need of Reflection Hack? PJonDevelopment | 13:24 5 Nov '08 |
|
 |
Hi, Bruno.
I was analysing your code but I didn't see the need for the Reflection Hack you used.
The GetHandler method of the WebServiceHandlerFactory simply calls the CoreGetHandler after raising the tracing enter event and making sure that the AspNetHostingPermission is satisfied.
After calling the CoreGetHandler it raises the tracing leave envent and returns the handler.
Your code bypass the security issue, as well the tracing events.
I just want to know why exactly you did that.
Regards,
Paulo Santos http://pjondevelopment.50webs.com
|
|
|
|
 |
|
 |
Hi Paulo, I'm not sure if I understood your question, so I think I should ask why you don't think the reflection hack is needed.
thanks! Bruno
|
|
|
|
 |
|
 |
Hi Bruno,
The public GetHandler method does the following:
Public Function GetHandler(ByVal context As HttpContext, _ ByVal verb As String, _ ByVal url As String, _ ByVal filePath As String) As IHttpHandler
Dim caller As TraceMethod = _ IIf(Tracing.On, New TraceMethod(Me, "GetHandler", New Object() {}), Nothing)
If Tracing.On Then
Tracing.Enter("IHttpHandlerFactory.GetHandler", caller, Tracing.Details(context.Request)) End If
New AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal).Demand
Dim compiledType As Type = WebServiceParser.GetCompiledType(url, context)
Dim handler As IHttpHandler = _ Me.CoreGetHandler(compiledType, context, context.Request, context.Response)
If Tracing.On Then
Tracing.Exit("IHttpHandlerFactory.GetHandler", caller) End If
Return handler End Function
That's why I don't think the Reflection Hack is needed.
|
|
|
|
 |
|
 |
Dim compiledType As Type = WebServiceParser.GetCompiledType(url, context) will not work. Thats why.
|
|
|
|
 |
 | Can you give me a whole example? JLKEngine008 | 21:10 25 Jun '08 |
|
 |
according to your description, Can you give me a whole example? e-mai: hy2001al@163.com thanks very much
|
|
|
|
 |
 | Can we use it in ASP .NET AJAX ? satriya | 0:10 18 Feb '08 |
|
 |
Bruno, great article ! Solve my problem. But I always got an error when using it inside ASP .NET AJAX framework.
This my simple code :
protected void Page_Load(object sender, EventArgs e) {
ScriptManager sm = ScriptManager.GetCurrent(this.Page);
ServiceReference sf = new ServiceReference(); sf.Path = "WSTest.asmx"; sm.References.Add(sf);
ScriptReference sc = new ScriptReference(); sc.Path = "Demo.js"; sm.Scripts.Add(sc);
}
This is my Demo.js code :
function Test() { WSLibrary.WSTest.HelloWorld(OnCompleted); }
function OnCompleted(result) { document.getElementById("message").innerHTML = result; }
if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
I can't use WSTest.asmx reference from code above. But if i use it by right clicking and choose Web References, then everything goes fine.
Or maybe I missed something ?
|
|
|
|
 |
|
 |
Hello Satriya, a quick workaround for this issue is to instead of adding a new httpHandler like
<httpHandlers> <add path="WSTest.asmx" verb="*" type="WSLibrary.WSTest" validate="false"/> </httpHandlers>
to web.config, create a plain .asmx file in your web project with the content:
<%@ WebService Class="WSLibrary.WSTest" %>
Let me know if it works for you.
Bruno
|
|
|
|
 |
|
 |
Bruno,
This info you have provided has been helpful for me, thank you. I have a large ajax type asp.net application that uses both aspx and asmx. I have used the web deployment project from some time now and I really don't like it. So, I got rid of it and now place all the "codebehind" code in a separate assembly. I was using the method you mentioned to Satriya by creating basically a stub asmx file which would then point to the appropriate class. But, I wanted to get rid of those stub files for asmx. I already did for aspx, but the asmx's were a little more tricky. Anyway, I had to change one thing. btw, I use c#
Your code (in c#)
private WebServiceHandlerFactory _wshf = new WebServiceHandlerFactory(); private MethodInfo _coreGetHandlerMethod = typeof(WebServiceHandlerFactory).GetMethod("CoreGetHandler", (BindingFlags)((int)BindingFlags.NonPublic + (int)BindingFlags.Instance));
IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string url, string pathTranslated) { try { return _coreGetHandlerMethod.Invoke(_wshf, new object[] { this.GetType(), this.context, this.context.Request, this.context.Response }) as IHttpHandler; } }
I needed to change this to:
IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string url, string pathTranslated) { try { return _coreGetHandlerMethod.Invoke(_wshf, new object[] { this.GetType(), context, context.Request, context.Response }) as IHttpHandler; } }
in other words, use the 'context' variable that was passed rather than the one in 'this'
This cleared up all the problem and everything works great. I'm not sure why the two would be different. Any insight there would be interesting.
gkelly
|
|
|
|
 |
|
 |
Hi gkelly, thanks for the info!
When you're using asp.net ajax, the handler for .asmx is another one, that's why the code doesn't work properly.
this other handler generates some additional javascript code and that's the reason to use the new handler I believe, I tried to use that new handler instead of WebServiceHandlerFactory and unfortunatelly it was again not working properly because it checks if the .asmx file exists.
I'll try to make a good fix for this in some days when I get some free time.
Does asp.net ajax work ok with your code? In my VB code I'm not using "this" that is "me" in VB, so I could say that my code is the same as your second one, but I didn't use the try block, which shouldn't be necessary but I understand why you're using this.
I hope to end up with a good solution.
Thanks again! Bruno
|
|
|
|
 |
|
 |
Bruno,
By the time I heard of microsoft's ajax library, I had already written an ajax engine and based all of our code on it. So, I really don't know how they compare. I really love programming ajax type apps along with c# even though calling it 'ajax' is weird since I didn't initially know it by that term. javascript is a really cool language and C# is awesome. I really don't prefer VB, but if you come from a VB background, I can see why it would be nice. I come from a C++ background. I don't know if this answered your question, oh well.
|
|
|
|
 |
|
 |
Hi gkelly, actually I just asked if asp.net ajax worked on your code with the try catch block Because it requests some additional js from the web service, and as the handler beeing used doesn't do that, it throws the exception.
Try to create a simple web service in a web app project and request for file.asmx/jsdebug and you'll see what I mean, then try to do the same request for your ws in the class library.
Bruno
|
|
|
|
 |
|
 |
according to your description, Can you give me a whole example? e-mai: hy2001al@163.com thanks very much
|
|
|
|
 |
|
 |
Hello,
Did you manage to find a working solution about this asp.et ajax implementation ?!
Thanks again for your code sample.
Regards.
Seb
|
|
|
|
 |
 | You solved my problem. Ashaman | 3:17 27 Nov '07 |
|
 |
I figured there HAD to be a way to do this, but I couldn't find any examples online. I had finally decided to start researching the way you have, but was not looking forward to it.
Thanks so much for publishing this great information.
You got my '5'.
|
|
|
|
 |
|
 |
Hi Ashaman, Thank you!
|
|
|
|
 |
 | Great Idea merlin981 | 5:30 26 Nov '07 |
|
 |
And very simple to implement.
|
|
|
|
 |
|
 |
Thank you!
|
|
|
|
 |