Running a .asmx Web service as a Windows Service - c#

I'm a total novice on asking questions on this forum - I hope I ask this question correctly.
The problem I'm trying to tackle is this: I have a Visual Studio 2010 project which is for a Web Service. The class which does the work is defined in a ".asmx" file. The class inherits from the "System.Web.Services.WebService" class.
It runs happily on IIS on a server. Clients can make SOAP calls to the Web Service and it actions the requests and sends a response. That's all fine.
The problem is that I want it to run on a Windows 7 PC on which I can't install IIS. So I wish it to run as a Windows Service (if possible). The only "client" of the service will be the user on that PC.
In other words, I wish to run all the code that is in my .asmx as a Windows Service (if possible).
In an ideal world I'd be able to re-use my existing .asmx (if possible), and not have to copy and paste all my code across to a new Windows Service solution.
So my goal is to find the up-to-date way of running an .asmx Web Service as a Windows Service. I'm hoping someone could point me in the right direction on how I accomplish this.
I've done quite a bit of searching, and it looks as though this is very much possible to do. The problem is that a lot of solutions out there, appear to be slightly out of date. Or I've got my concepts rather mixed up.
Based on "How can I deploy my WCF Service without IIS?", I've had a look at a few things.
The closest I've come is this: "https://msdn.microsoft.com/en-us/library/ms751414.aspx". However, in this example, the actual class which does the work (the calculator) is actually contained in the service itself. I would have thought you could have separated them out. In other words, have the service create instances of a class that comes from my .asmx file.
The second closes I've come across is "https://msdn.microsoft.com/en-us/library/bb332338.aspx#msdnwcfhc_topic4", however this is .NET 3.0 and VS 2005. I'm also struggling to understand how to link my existing class into the service.
The other solutions I encounter suggest adding references to "Microsoft.Web.Services3.dll", "System.Web.dll", and "System.Web.Services.dll", although a few people seem to think this is called WSE which was updated to WCF in .net 4.0 and so I should not be using it.
Any pointers as to where I get started?

In an ideal world, you would switch to WCF, as it can easily self-host, host in a service, etc. And there are plenty of examples out there. It is easy enough to migrate the code from ASMX to WCF. But this is 3.5, as NetFX (WCF, WF and WPF were released under 3.5).
With ASMX, you need a server to host with. You can create a simple "server" with the HttpListener class. This may be heavy enough for your purpose.
https://msdn.microsoft.com/en-us/library/system.net.httplistener(v=vs.85).aspx
IIS now has a hostable core, which can be used with newer versions of .NET, but if you cannot install the newer versions and have to leave the client machines at 3.0, it is probably not your best option.
You may be able to dig up old source for Cassini, which was Microsoft's implementation that eventually became the hostable web core.
Back in 2008, someone snagged the server in VS, which might be an option. Note that the version on this page is for VS 2008, which means 4.0:
http://www.codeproject.com/Articles/23939/Light-IIS-Run-Asp-net-without-IIS
Ultidev has a server that is reported to self-host: http://ultidev.com/download/default.aspx
Hope one of these helps.

Just for completeness, here's how I solved this:
In the end I went with running IIS on client PCs and just continued using the asmx.
I found that converting the asmx to WCF to be quite tricky. To be precise, it was the thread handling within the asmx (thread handling coded by someone else), that I found to be quite hard to convert. To explain further the asmx which I was trying to convert, did all its work in a class which inherited from "System.Web.Services.WebService". It could therefore, create an "Application" instance, which it then used to do its thread management.
So rather than try and do the same thing, using "System.ServiceModel" (which doesn't allow me to create an "Application" instance), I thought it easier to just to use IIS on the client PCs. I figured this was a better use of time than recoding a fairly complex asmx. A bit defeatist I know.
Kind regards to all.

Related

Separating existing web project

I have inherited an existing .Net/angularJS project. We have a need moving forward to allow customization per client, while still maintaining synchronization through version control (in this case, git).
I'm not a .Net developer--my .Net experience is limited to writing a service a couple of years ago, starting the BrowserStack tests for the project, and the occasional foray for code review type activities. I'm primarily a Flash/Flex developer with a fair amount of ASP Classic and some PHP experience.
My preliminary research seems to indicate that I can do what I need to do with a git subtree, but I need to find where the seams should be to separate out the custom stuff from the shared code. Right now, the HTML and JS are in the same directory as the web services. My first order of business will be to separate those out, but I don't completely understand
Why everything's all in one place to begin with
What the implications are of moving things (project settings, paths, etc.)
When I wrote the service way back, I do remember that we had to scrap the service because the server we had the site on didn't support that version of .Net and it wouldn't work across domains so I could host the service on a server where it would work. I know that things have changed and there's now a way to allow that, but I figure that's the sort of problem I should be looking to avoid as I do this.
I figure I can't be the first person needing to make this kind of separation in a project I think started from the monolithic web project template, but because of a short deadline and a lack of knowledge of .Net, I'd feel better if someone could point me in the right direction or at least alert me to some of the gotchas I should plan to encounter.
Are you Trying to decouple the Projects. If so than this might be a good help.
http://www.codeproject.com/Articles/439688/Creating-ASP-NET-application-with-n-tier-architect
One of my recent project was almost the same that you mentioned above, So I ended up scrapping the old version and Create a brand new Project and Decoupled the related stuffs in the solution.
The best way of understanding stuff is to make sure you seperate the Client Side (Javascript/Htmls/CSS) and Server Side (EF/SP Calls/DTOs etc) by creating different project to the same solution.
Hope this Helps.
So I kept digging, and I finally found a pair of tutorials that address exactly this issue.
Creating an empty ASP.Net Project Powered by Angular JS Using Visual Studio
AngularJS Consuming ASP.NET Web API RESTful Services
In a nutshell, you copy the client's url from the properties panel to the service properties panel and add '/api' to the end of the URL and allow VS to create a virtual directory for you.
Now for my next trick, figuring out how to publish it...

What are the repercussions of changing a ColdFusion-generated WSDL web service from RPC-encoded to document-literal?

I inherited a few web services that are WSDLs generated by ColdFusion 9. The CF9 default is RPC-encoded, so that's what they are. However, it's recently come to my attention that newer versions of the .NET framework (or maybe it's newer versions of Visual Studio) don't like RPC-encoded WSDLs. In testing (in C#), I verified that VS 2013 only properly consumed the service when it was in the document-literal style.
I'm of course open to changing the style to be more universally usable, but this web service has been in the wild for some time (and is used by a number of people, I'm sure), so I want to ensure I have a handle on what the possible repercussions might be. I'm also wondering if it's possible to get ColdFusion to generate two different WSDLs (or allow setting of the encoding on the fly?). Basically I'd appreciate any advice on the best way to make this compatible (while maintaining backwards compatibility). Thanks.
If you're OK with having a second URL for the document-literal style web service you could just extend your existing CFC. Your new CFC would have all the same functions and logic of the main web service. It would also prevent a There would be no additional code to maintain. The only unknown for me is if this will create any significant additional overhead.
<cfcomponent extends="yourExistingCFC" style="document" output="false"></cfcomponent>
I did try setting the document type to document-literal on one of my test web services. SoapUI was unable to parse the document-literal WSDL once changed, but Visual Studio could. From this, I would be hesitant on changing the document style of your existing CFC, for you cann't tell how all the client environments will handle the change.

Implementing a Web Service Server in Windows CE 2013

I have a smart device (Windows CE 2013) that just got the requirement to be controlled from a number of different devices, to do this, we decided to serve a web page from the device that allows it to be controlled.
I've also read that compact framework doesn't support ASP.NET so I'm intending to serve a static webpage that contains a javascript application that calls web services hosted on the device.
I also found this link explaining how to serve a SOAP Service in C++, but it seems old, and I'd prefer to do this in C# as it's my preffered language and I already have some code on it
I'm not quite happy with this solution, am I missing something? Can't I really do this in C#?
You could try this library for .NET https://github.com/ServiceStack/ServiceStack .
It is a free in case if you are using branch v3 form a github.
There's nothing built-in in the CF that provides web server capability. Windows CE has always shipped with an HTTPD server, but, honestly, it sucks and can't be integrated with managed code anyway.
We solved this problem long ago by creating our own IIS-like web server implementation (available commercially). You could do something similar as well - it's just a lot of Socket work. That trivializes the complexity of concurrent request handling and providing an IIS-like object model, but you get the idea. Basically you have to write the whole thing.
The main answer to this is to use Mongoose (or the MIT-licenced equivalent Civetweb). They are C webservers designed for just your task - an embedded web server.
They are really easy to implement, 1 C source file added to your project, give it an array of options, and you're done. See the examples. It has plenty of features and is fast, and small (40kb compiled!). They say it takes 5 minutes to get going with it, and they're right - I tend to use it to add webserver functionality for normal applications now.

Silverlight - Send/Receive Data at runtime with JAVA

Yesterday I asked about what technology should I use to create dynamic web content here:
PHP, AJAX and Java
The suggested methods were JSP, JQuery, etc. But I thought maybe because I'm a .Net developer and I don't have any experience in web development but I have experience in WPF and C#, maybe I should go with Silverlight but the main problem here would be how can I communicate with the core part of my system which is implemented in Java?
So the main question would be: What is the best [and easiest to learn] method to send a piece of data to the Java part, get the result and use it in silverlight? A tutorial or simple example would be nice.
Thanks a lot in advance.
You should use Java Web Services as stated. Use WCF to invoke the Java WS by adding a Service Reference in Visual Studio by its url, then use the proxy classes generated automatically (located in Reference.cs) to invoke the WS. This is easy but remember SilverLight WS invocations are always asynchronous, so you must cath the OnCompleted event to get the results of the invocation. WS are slow but if the machines are in the same LAN, invocation could take a few milliseconds.
I think pipes are not your solution as SilverLight executes in a Sandbox and have many restrictions on what you can do.
This will depend on many factors, however a relatively easy approach would be to use Java Web Services. On the .NET side, WSDL will be picked up and transformed into proxy class by WSDL.exe from the Windows SDK. If, however, these two systems are on the same server (and intend on staying this way), you may decide to use pipes.

Web UI for Custom C# App

I have a application written in C#, installed as a [WCF] windows service, which will be running on headless machines. I would like to provide a nice web UI for it, but I'm not sure how to host it. After looking at embedded web servers such as Cassini, none seem ready for this without a ton of web server code. I would like to find a package that would let me design in something like Silverlight. Also, I need to be able to provide a simple installer for customers that doesn't involve "go get IIS", etc.
I saw this post that seemed close, but didn't really answer any of my questions, except affirming that its possible. I'm really looking for specifics on how to make this happen.
Why go silver-light route unless you need very rich/flexible UI? I would suggest using WCF itself to serve HTML over HttpBinding. Have a look at few articles regarding the same:
http://blog.iserviceoriented.com/index.php/2010/01/23/building-a-basic-web-server-using-wcf/
How do I create a simple Web Server using WCF without the ServiceHost class?
REST support by System.ServiceModel.Web namespace should make the task even more simpler (than described in above articles).

Categories