Problem making an Interface

Using (or providing) components based on the "Win32" framework

Problem making an Interface

Postby PGilbert on Mon Feb 17, 2020 6:07 pm

I am evaluating DotNetBrowser and I need to make the following interface as described here. The interface looks like this:

Code: Select all
    public class HttpsHandler : IProtocolHandler
    {
        //This method should provide the response for the specified request
        public IUrlResponse Handle(IUrlRequest request)
        {
            string htmlContent = "Request Url: " + request.Url + "\n";
            return new UrlResponse(Encoding.UTF8.GetBytes(htmlContent));
        }
    }


The following code does not work:
      :Interface HttpsHandler

∇ urlResponse←IUrlResponse request
:Implements Method IProtocolHandler

⎕USING∪←⊂'DotNetBrowser.Protocols,C:\DotNetBrowser32.dll'

⎕←request.url

urlResponse←'to do'


:EndInterface


The error is:
declared interface member not found. Either the member does not exist or the function syntax is incompatible ":Implements Method IProtocolHandler".

In the WS with the same ⎕USING IProtocolHandler is found (the complete name is: DotNetBrowser.Protocols.IProtocolHandler).

What it is that I am doing wrong? Thanks in advance.
User avatar
PGilbert
 
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Problem making an Interface

Postby JohnD|Dyalog on Tue Feb 18, 2020 4:16 pm

Hello Pierre,

I've not tried your example, but I suspect you just need the function name:

Code: Select all
:Implements Method IProtocolHandler.Handle


Best Regards
John Daintree.
User avatar
JohnD|Dyalog
 
Posts: 74
Joined: Wed Oct 01, 2008 9:35 am

Re: Problem making an Interface

Postby JohnD|Dyalog on Mon Feb 24, 2020 9:05 am

Hello again Pierre,

There are a couple of key issues here.
* You need to define a class that implements the interface. Your code is defining an interface
* You need to tweak your :Implements statement as per my previous suggestion.
* You need to "emit" the code as a .NET assembly.
** The interpreter does not create MSIL and .NET Metadata for classes as you close the editor.
((In the past you may have used the “Export…” item on the session “file..” menu to create . NET assembly as a dll. Also on the session menu is “Export to Memory…”, which creates the assembly “in memory”. This is required if you want to use the .Net nature of a class without creating a file (which is what you require in this case). 2100⌶ performs this “Export to memory” without the need to select the menu item.

This has worked for me with the following code:

      ∇ test
[1]
[2] ⎕USING←'DotNetBrowser,e:\downloads\DotNetBrowser.Chromium32\DotNetBrowser32.dll'
[3]
[4] 2100⌶0
[5]
[6] browser←BrowserFactory.Create ⍬
[7]
[8] browser.Context.ProtocolService.Register('https'(⎕NEW HttpsHandler))


:Class HttpsHandler : IProtocolHandler
:using ,
:using DotNetBrowser.Protocols,e:\downloads\DotNetBrowser.Chromium32\DotNetBrowser32.dll

∇ urlResponse←Handle request
:Implements Method IProtocolHandler.Handle
:Signature IUrlResponse←Handle IUrlRequest


⎕←request.url

urlResponse←'to do'


:EndClass
User avatar
JohnD|Dyalog
 
Posts: 74
Joined: Wed Oct 01, 2008 9:35 am

Re: Problem making an Interface

Postby PGilbert on Mon Feb 24, 2020 2:33 pm

Many thanks John, it is working now.
User avatar
PGilbert
 
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada


Return to Windows: GUI, COM/OLE/ActiveX

Who is online

Users browsing this forum: No registered users and 0 guests