WCF on Linux - is it worth the effort - linux

This is my first question here, so please don't shoot.
I've been playing with Linux recently (Ubuntu 9.04 and openSUSE 11.1) with focus on web services. The simple Hello World web service (as described on mono-project.com) works fine. Now I need to step into the wonderful world of WCF (I'm familiar with the concept). And I'm stuck. I've installed MonoDevelop and mono-wcf package (including all the dependencies) and as you can assume I can't write simple WCF server (well, I can write it, it just won't compile). I'm missing some references which I can't find: The type or namespace name 'ServiceModel' does not exist... and when I add System.ServiceModel reference (for which I have to change to Moonlight/Silverlight project type or I don't even see it in Packages) I get: The type or namespace name 'ServiceHost' does not exist, and I just don't know where it is.
What am I doing wrong? The same code compiles and runs fine on Windows (VS2008).
Please help. And still don't shoot.

Although there is work currently being put into WCF on Mono (mainly around the parts of WCF that are included in Silverlight), the WCF stack is largely incomplete. My impression is that only the most basic of operations are functional.
Regular web services, on the other hand, should be fully functional.

Related

Azure Function gives error: System.Drawing is not supported on this platform

(If this question is poorly worded, could someone please help me clear it up?)
I have an Azure Function (2.0) which relies on some System.Drawing code. I've added a NuGet reference to System.Drawing.Common (4.5.0).
After publishing the app, however, when the function is called, it produces the error:
System.Private.CoreLib: Exception while executing function:
[MyFunctionName]. System.Drawing.Common: System.Drawing is not
supported on this platform.
As far as I'm aware, System.Drawing.Common is supported on .NET Core now, which I believe is the environment in which my Azure Function is running. The actual project is a .NET Standard 2.0 project, though.
I am confused as to how to resolve this. I've tried converting the project to a .NET Core 2.1 project but that led to bizarre errors related to "Metadata generation failed" and an inability to find System.Runtime.
My project references Microsoft.Azure.WebJobs.Extensions.EventGrid (2.0.0-beta2) if that's relevant.
It's not about the CLR, it's about the sandbox.
System.Drawing relies heavily on GDI/GDI+ to do its thing. Because of the somewhat risky nature of those APIs (large attack surface) they are restricted in the App Service sandbox.
Win32k.sys (User32/GDI32) Restrictions
For the sake of radical attack surface area reduction, the sandbox prevents almost all of the Win32k.sys APIs from being called, which practically means that most of User32/GDI32 system calls are blocked. For most applications this is not an issue since most Azure Web Apps do not require access to Windows UI functionality (they are web applications after all).
Try to find an different library that doesn't rely on System.Drawing/GDI, like ImageSharp.
A little update can help a lot of people.
Now you can switch your Azure Function to v3:
in Function app settings panel -> Runtime version ~3
With this setup, your code run in a sandbox that support Core 3, (you don't need to rebuild your dll to Core3, i run my .net core 2.1 dll without errors), and surprise... you don't get this exception anymore:
System.Drawing.Common: System.Drawing is not supported on this platform.
Because the CLI can found GDI/GDI+ that need in the subsystem.
Now i can convert html to pdf without go crazy.

ServiceStack and Fody Costura

I'm pretty new to ServiceStack, so apologies in advance if the nomenclature is not 100%.
I create a test self-hosted application and the ServiceStack Service was in the same assembly as the mainline code. All good.
I then moved the code to production use, and service now lives in a separate assembly to the main code. Initially, I have a test harness that I use to make sure everything works fine, and then a windows service that references that same assembly. Fairly sure this would be normal usage.
The test harness works fine, however for production use, I have used Fody Costura to embed the assemblies into a single executable (makes it easier to copy from dev machine to production machine was my thinking).
When using Fody Costura to embed the assembly into the executable, ServiceStack returns an error during the Init() (invalid path). I have tested this and it seems that the ServiceStack Service class needs to be in a physical assembly file that can be loaded, and not a resource.
Is there are known work around for this, or do I need to retain the code in its own assembly for ServiceStack to work?
Thanks in advance.
Craig
I'm not familiar with Fody Costura impact, but the ServiceStack.Gap project shows how you can ILMerge ServiceStack into a single cross-platform .exe.

Developing a web app with Mono (opensource .NET) any examples?

I am a Java, Scala, Python web app Linux guy. I want to play around with Mono (particularly F#) for web development.
I am just looking for an example web application written in Mono perhaps in Github (any CLI language is fine). I have tried googling and cannot find a good starting point (or if its even possible).
From what I gather I could sort of combine:
Fast CGI (nginx, lighttpd)
Mono
Spring framework .NET (I can't even tell if it will work on Mono)
Advanced apologies if there is a glaringly obvious resource (web site) that I missed.
(useful site: http://www.tryfsharp.org/Resources/GetMono.aspx)
To get F# dev environment for Mac/Linux setup:
http://www.tryfsharp.org/Resources/GetMono.aspx
For Ubuntu 12.04 specifically:
http://datachomp.com/archives/running-asp-net-mvc4-on-ubuntu-12-04/
To Get Fsharp to work with MonoDevelop 2.6 or greater you have to use one of forks of:
https://github.com/fsharp/fsharpbinding
Nancy looks like a good URL routing option which is all I really need:
https://github.com/NancyFx/Nancy
And for F# Mono stuff for Nancy including Djano templating:
https://github.com/NancyFx/Nancy/wiki/Building-Nancy-on-Mono
You can use the command line NuGet install tool (which is basically like Javascripts npm or Java's maven):
http://nuget.codeplex.com/releases/view/58939
Once I install the Fsharp Powerpack I should have in theory LINQ to use for persistence.
And If Nancy does not work out there appears to be a standard called OWIN (it appears to be analogous to Python's WSGI).
Other OWIN compliant projects: http://owin.org/#projects
UPDATE
Looks like ServiceStack has some good stuff also and seems to be gaining some traction. In terms of Mono you mainly want to look at daemon doc.
Check out XSP (about halfway down this page)
Mono & ASP.NET
And besides WebSharper which Daniel mentioned there's also Bistro.
Hope that helps.

Is it possible to intercept dns queries using LSP/SPI?

I wrote my own LSP which is working fine. However, I can not catch dns queries. For example there is no function like WSPGetHostByName or WSPGetAddrInfo.
My lsp also supports UDP protocol but it is not working. If I run nslookup from console (cmd.exe) it seems working but i can not catch gethostbyname. Does anyone know how to do that? I don't think writing NSP (Name Service Provider) is a solution. But I might be wrong.
Thanks
We have developed a LSP that can "intercept" DNS queries. The only way to do it is by hooking into all of the DNS functions, keep in mind there are a few challenges you need to solve:
You need to use a good hooking library that will support both 32bit and 64bit code.
The library license must be right for your application, there are some free libraries, but can be used freely only with free projects.
When you hook the functions, you need to make sure not to modify certain values that are not IP based and defer the query to the real function.
Intercepting UDP will not work since the queries are going out from MS DNS client, so unless you write a low level driver like: TDI, NDIS or WFP you must hook the functions (or write a NSP). NSLookup works for you because it creates the DNS queries itself.
My solution would be as follows:
Take the well known web browser: firefox.exe
copy it into a new name: icefoxy.exe
modify the EXE so it will load a custom DLL.
I have already done this a few months ago, but since Firefox is constantly getting updates, that means:
EITHER: keep one version and do not update (at your own risk, may cause security problems since that means vulnerabilities will not be fixed)
OR: Update your modification every time firefox.exe changes.
The DLL can easily be written using Delphi.
The Firefox modification needs assembly language, unless you know how to download all necessary files to compile firefox yourself, have access to a C/C++ compiler (likely mingw-gcc), and be prepared of the fact that there are 2 mutually exclusive standards of C++, and if your g++ (part of the gcc suite) is incompatible with your Firefox source, then your attempt will fail.
I am not a C++ expert myself, so I took the (for me, at least) easier route using machine language, that way I do not need to be a C/C++ expert to get the job done.
Some relative points:
What functions must be hooked to intercept all Firefox's access to dns server(s) ?
I noticed, that if you load a Delphi DLL into Icefoxy.exe (a renamed copy of Firefox.exe)
then a Delphi form's colors are missing, eg. if you set (either in object ispector or in code):
Label1.Color := clLime;
you still see a label withOUT lime background color. I do not know the exact reason, but it seems that Delphi VCL is relying to be used in an EXE, and when you use Delphi VCL components inside a DLL instead of an EXE, some things (such as color) does not work as intended.
I'd be happy to post my code (both assembly language modifications to Firefox and the Delphi DLL source code) , but how/where can I post it so it is publicly viewable ?
I used Delphi 7 to make the DLL.
if you use Delphi 2009 or later, you need to take extra care that any string data passed between the Delphi code and any non-Delphi code has the correct encoding, due to the fact that In Delphi 2009 and all newer versions, the type String is an alias to unicodestring, where in older Delphi versions, the type String is an alias to AnsiString.
At the time I did this, it was just a small experiment to find out if I can force Firefox to load my own DLL inti it's process address space.
Another interesting idea would be to get access to the DOM (Document Object Model) of Firefox from a Delphi DLL, that would give a working alternative to using TWebBrowser (based on ActiveX version of Microsoft's Internet Explorer).
I know there have been components like TWebBrowser based on Firefox, but their problem is that nobody cared to update them for a very long time, so they are compatible only with some very outdated version of Firefox.

how to create inifile in Delphi Prism for .net that will work on window and Linux(Mono)?

My Delphi Prism program needs to create and read and write into an inifile, but I think I noticed Delphi Prism doesn't really support any sort of Inifile structure. (Correct me if I am wrong.)
This leads me into talking about ShineOn library file, which supports inifile. However, it crashes the program when you run your program on Linux under Mono. It doesn't matter if I use any methods from ShineOn or not. As long as the ShineOn library file is listed under uses keyword, the program does not run but crash completely on Linux. Can you create inifile in Delphi Prism for .net that will work on window and Linux(Mono)? If so, how would you do it?
I did search for answer on the internet and Stackoverflow, which led to me C# Class INI file. I thought, it was promising until I noticed that it needs to load Kernel32.dll file to work. (Again correct me if I am wrong). Apparently, there is very little information on the Internet about Delphi Prism Inifile.
Actually you really shouldn't use .ini - Files in .NET (or Mono) environments at all. .NET and Mono offer complete App.config XML-Configuration infrastructure and you should leverage this for your applications. There are a lot of advantages because everything is available type safe and all is covered in the System.Configuration Namespace.
See http://nini.sourceforge.net/
It documented to work on both MS .NET and Mono

Resources