Consuming IIS-hosted WCF Service from Linux Web Application - c#

I was tasked at work to create a web application (viewable in Firefox on Linux!) that displays results in a tabular format using data exposed by a WCF service (written in C#) hosted on a separate Windows 7 machine on the same network. Rather than returning formatted HTML, the WCF service returns structs and it will be up to the client application to take these objects, pull out the data, and format it.
Unfortunately, it has been a couple years since I have worked with any sort of web technologies. What is the best approach to solve this problem? Is there anything more current than REST/AJAX/JSON/jQuery technologies? If anyone can point out some helpful and current resources on the proper way to accomplish this, it would be most appreciated.

Use a SOAP framework to consume the WCF service. Configure WCF to use SOAP (one of the HTTP-bindings).
Webservices are easy to consume these days thanks to a standard RPC format (SOAP) and libraries supporting it. You can surely find a SOAP client for any language you are proficient in.

Checking back in here to report my own solution for this problem. I ended up going a bit of a different route that produced the simplest solution for the situation. Instead of consuming any services on the Linux side, I simply made an ASP.NET website on the Windows/IIS side (where it is easy to consume the WCF services right from Visual Studio), and then just render the website on the Linux side via the URL in a Firefox browser. For me, that fulfilled the customer requirements and was perfect, although this may not be the best approach for others that need to work with or manipulate the data in some way.

Related

Getting a web service and using android to consume them?

I have been looking up on youtube regarding Web Services being consume using android. Most of the video are all 1 or 2 years old. Is this doing outdated? is there a better way to do this? currently i am in a company and i was assign to have a android version of their webservice.
I was told to create the service with sql using Visual studio.
Create the android UI and using the services to pull the data.
Am i doing it right?
What is the better or ideal way of going about this?
Should i add JavaScript or something like that?
I have been looking at RESTful , Soap , Json and Wcf. But what is the best way to go if i have to start everything from scratch?
-Programs/System that i am using.
Microsoft Visual Studio Express 2013 for Web
SQL server
IIS express
Android Studio
*I was told to only user framework 4.0 for Visual studio
You can use WCF (SOAP), WCF (RESTful) or WebApi to create a service, both has it's own advantages and disadvantages. You may want to take some time to look at your requirement and then decide what type of service you want to develop. SOAP uses a more complicated messaging pattern using XML, where as REST uses the standard HTTP protocol and methods to communicate and transfer data. But if you are planning consume this service across of variety of applications like mobile, web, desktop, client side script interaction etc, you may consider developing the service as a RESTful. More information on SOAP and RESTful and for detailed understanding you may refer to this link
Understanding SOAP and RESTful

Why i have to use WCF instead of web service? [duplicate]

This question already has answers here:
What are the differences between WCF and ASMX web services?
(5 answers)
Closed 9 years ago.
its my first question on stackoverflow.
i have read a lot of articles that said developers should use WCF instead of web services, because it could be hosted on different hosting environment,etc...
but what i'm thinking of is that i can call web service form any project using HttpRequest.
so why i have to use WCF.
With WCF, the out-of-the-box binding is BasicHttpBinding, which is just SOAP, the same as .asmx web services. As a client, you can still access it the exact same way you accessed .asmx services - either by generating a proxy from the WSDL, or normal HttpWebRequest or whatever you were using before.
The benefit is all the additional options you get with WCF, like security, the possibility for different bindings, standalone hosting, and a whole lot more. Plus it's the direction the .NET community has chosen, so if you want to stay relevant in a .NET service-based world, you'll need to learn it.
There is a lot more to WCF than there is to an ASMX web service. If an ASMX web service suits your needs then it is fine to use one, however you might find that there are problems that are easier solved using WCF than and ASMX web service. There are also many things that you can do using WCF (remember its a framework not just a way of creating a web service) that you simply can't do using an ASMX web service.
Creating WCF services instead of ASMX web services even if they serve the same purpose may seem like added complexity for no added benefit but it is a good way to start to learn WCF.
You don't have to use Windows Communication Foundation. It is ultimately going to be your choice. Also the project may contribute to your needs.
However, the primary reason you would use Windows Communication Foundation would be the following reasons:
Provides a varying array of communication across several platfrms: HTTP, HTTPS, TCP, MSMQ, and Etc.
It provides additional Security.
It has a better means of Serialization and Deserialization.
It provides more code re useability.
Different forms of hosting.
Those are some of the keys, the most important was it's design to save developers time in web based communication. It also is a methodology to bring Service Oriented Architecture as well, for fully agile applications.
Another important note is to realize that Microsoft has limited support for standard web services; now that they've implemented WCF technology.
Hopefully that helps.

adding a WCF to existing website or have a new service?

I am a total newbie to the WCF world. I have an ASP.net (v4) website running on our dedicated windows 2008 server box. I'll refer to the website as, webisteA.com
I'm creating a new website, websiteB.com.au and I'd like to expose the functionality in WebsiteA.com to the new site. Things like logging in, registering in the database etc.
I think the best way to do this is to create a WCF service which sits in WebsiteA.com - but I am struggling to find any tutorials on how to do this. There are lots about creating a new project, but not that many about adding a WCF service to existing websites.
Is this the best way to do it? In the future I'd also like to use the service for mobile apps in the future too - not sure if that will make a difference.
OR - do I create a new service in a new app which is totally seperate to websiteA.com and websiteB.com and host this as website0.com and expose the database via that?
The questions I don't have answers for are...
is it restful? Do I use XML or JSON?
Baiscally, I want to be able to use it like an API - for example, saying "show me all the members who meet criteria X".
Thanks for any information.
ps) I have visual studio express 2010 c# (and a trial of studio pro)
You can certainly include WCF within the website A project - but have you considered the ASP.NET Web API? I haven't used it yet - but did use the earlier WCF Web API which spawned it.
Neat features include Content Negotiation (if the client asks for XML the API sends XML. If it asks for JSON is gets JSON) and a lot less config cruft (WCF web.configs are dreadful and completely overcomplicated IMO)
It's probably a lot easier to make a RESTy API with the ASP.NET Web API than with standard WCF.
A great open-source .NET solution is NancyFX which is really worth a look too.

Accessing an SQL database from a Silverlight client (no web project)

I want to access a remote SQL database for my Silverlight client. I know that there are various ways to do this (Entity Framework model, Linq to SQL), but all of those rely on something in the web project (or, at least, all of the tutorials I've read do). What's unusual for me is that there is no web project, which of course prevents me from using various assemblies.
The only thing I do have which might be useful is a WCF service running on IIS, which will have less limitations (and I can add that as a service reference in my SL project). But I'm not even sure if this is a feasible option for this problem.
Any solutions or suggestions would be great.
Thanks.
Edit: Thanks for the suggestions guys, but here's a little more: I am making an individual XAP that is loaded into something else (someone else's project is importing and loading the XAP files), so I don't have access to the web component. The loader itself will be hosted within a website (at least, I assume it will be).
I already have a WCF service set up which is currently hosted in IIS, so I can potentially create something here. How? Well, it seems I can generate the ORM classes using SQLMetal.exe, and then import that code into the WCF service. This will allow the service to make calls to the remote database and have that data returned in C# classes. The perhaps I'll make those data classes as ServiceContracts and pass the data that way. What's the problem here? Well, to be honest, I'm not really sure how it would work. I mean, I call the WCF Service from the SL application, which does its thing. It then must contact the SL application (I have no idea how to do that part) and send along a load of data. It would be great if someone had has experience of this and would offer some suggestions. I know it's not really how you're supposed to do it, but I've drawn the short straw so I'm stuck with it.
Ok, so if I understand it correctly, you use a Silverlight application (XAP) which is started locally from a network share or something? Because why would you not have a web project when using Silverlight? (is there no server available to host it?)
But ok, when that is the case, you can access a WCF service from Silverlight. However it has some limititations. For instance you can only use asynchronous calls to the service, and you can only use WCF basichttpbinding as binding for the WCF service.
See: http://msdn.microsoft.com/en-us/library/cc197959%28v=vs.95%29.aspx
First, I would recommend you use WPF instead of Silverlight for this project. If you're not using this as a web client, then WPF is a million times easier / better.
But if that's not a possibility:
You can write a self-hosted WCF service and run it somewhere accessible. Self-hosted will allow for WCF connections to connect without the IIS necessary. In your self-hosted program you need:
Front end WCF defined
Back end SQL database
Depending on how smart this client needs to be, a BusinessLogic layer to transform the data from WCF to SQL.
Silverlight is sandboxed, so it can only access its own Web application. Therefore, your best bet is to include a WCF or ASMX web service in your web application that handles the DB access.
If you don't want to run a sandboxed UI on a Web application, you cannot use Silverlight but should use WebForms or Windows Presentation Foundation (WPF) instead.

Direction needed for self hosted web server for html, json and websockets

Background
I have a windows console app written in C# which needs UI. I started using WPF, but as I come from a web background, I want to use html, and some features of html5, including web sockets for real time communication with another application.
Initially, I'll use a web browser as the UI, though I may later host a web browser in the main app. This bit doesn't concern me at the moment.
After a lot of googling/reading, I'm going round in circles. It looks like WCF can be used to serve html, json based web services, and possibly web socket streams.
A lot of googled info relates to pre .NET 4.0 community projects. Even post 4.0 there are several NuGet packages which seem to me to overlap what is already in the framework. To a WCF noob, it's all a minefield.
So, what areas of .NET 4.0 WCF and the various open source projects should I be concentrating my efforts on.
Requirements
I require a lightweight self hosted web server. It cannot be IIS based, as users will not have it installed. The server (or servers) must:
Be able to server complete web pages, including html, linked images, css and js files. C# MiniHttpd does the job well, but is not based on http.sys. HttpListener seems to be the core of what I want, but I haven't found a complete web server project based on it.
[optionally] Be able to parse those pages through asp.net or razor
Be able to respond to web service call via json. This bit I have a working example using System.ServiceModel. Is this the right way to go?
Be able to work with the emerging Web Sockets standard. SuperWebSocket is actively developed, but doesn't appear to be http.sys or wcf based.
Preferences
I would prefer to stick to one basic stack for all 3 of my main requirements - and I suspect WCF may be that platform.
I would prefer an http.sys based approach for all three requirements, so I can reserve the relevant url/port/namespace combinations and prevent conflicts with other web servers or services
Although other SO questions may help with individual aspects of my requirements, I need advice on a more holistic approach.
Ok, answering my own question feels wrong, but...
I have since found a great CodeProject article that provides an easy to use self hosted web server for serving the html, css, js and images, and serves the json requests.
Developing Web 2.0 User Interface for Self Hosted WCF Services using HTML5, CSS3 and JQuery
I still have to settle on a WebSockets solution, but the above project is as close to what I need as is possible at the moment. It doesn't support rendering asp.net or razor, but these were my lowest priorities, as I'm happy to use only pure html and javascript for the front end.
I'll try to post more specific questions in the future :)
Except for your WebSocket support requirement, the OpenRasta framework currently supports what you describe. It definitely can run in http.sys and can be used for both creating REST services and as a web app platform. It also supports Razor and other view engines. The link page has a good comparison chart toward the middle that compares it with ASP.NET MVC & WCF.
In March 2014, a solution which fits my original requirements is ASP.NET Web Api. It can be self hosted, and can apparently be set up to serve html etc as well.
Is it possible to serve a web page from a self hosted web API in a windows service?

Categories

Resources