A RESTfull search service Question - c#

I have a SQL Server (2008) database that contains address details that i want to make available to search as a rest service.
All that needs to be available is the ability to pass an address or part of an address and the service will return the potential candidates, much like yahoo or googles rest services.
My question is, from a high level what is the best approach to take for this?
I am using .net 4 and VS2010 but i have never made a rest service before.
Any links to similar articles or advice on the best approach would be appreciated

I've included a link to a very basic tutorial on making your own restful web service. Publishing web services aren't that difficult especially when no authentication is involved. Essentially you need to define a new class that inherits IHttpHandler interface, implement a couple of methods including the ProcessRequest inside which you can write text into the Response object. You may have to look into the Request object for query parameters (if you need to) and query your db accordingly.
http://www.codeproject.com/KB/aspnet/RestServicesInASPNET2.aspx

Related

Xamarin Restful Services (get put post delete)

We need URL while we are creating a connection to SQL
but how can i create URL? I could not find anything.
You need to create a web service connected to your database. Then, you will be able to interact with this web service (which will access database) from your Xamarin application using URLs, and HTTP get, put post and delete. As Jason said, creating a RESTful API is a good idea. You'll find plenty articles about that, the one I used to learn basics is there :
https://learn.microsoft.com/en-us/aspnet/web-api/overview/older-versions/build-restful-apis-with-aspnet-web-api

Password protected page

I would like to add a password protected page to my WPF modernUI application and could use some help with it.
First of all I don't really have a clue how to handle this stuff correctly in my case.
My application is used on several machines. The protected page should be some kind of admin-page to edit a database that is used by the app.
My idea is, that there is only one Admin-account. But this account can be used from any machine. The admin should be able to change his password. So there must be some kind of encrypted password file on the server which can be accessed from any machine. I don't want to store the password within the application, as this would mean that the admin has to change his password on every machine.
So my question is: What is the best/safest solution for my idea? I'm just looking for hints as I don't have a clue what to search for.
The best Practise nowadays for distributed client applications who share a Database is indeed not to have direct access to the Database.
What you need is a WebService. A web service can be anything. It just has to be hosted somewhere. It can be an ASP.NET application, a WCF Service, or even something not .NET related like a PHP or Java application.
The communication between your application and your WebService depends on what you decide to use. Today a lot of people are using so called REST APIs which use either XML or JSON as data transfer format and use the HTTP protocol.
Its not hard to implement such an API since there are ton of Libs and Solutions out there.
You could use RestSharp for the communication at your client side. Which is straight forward and simple. You could also consume a WCF Service. Which is hosted in IIS somewhere.
However your Problem is nothing special and there are several solutions available. The decision is on your side since it depends on a lot of things such budget, available infrastructe etc.
Your question is quite broad but as far as WPF is concerned you could implement custom authentication and authorization in your application by creating classes that derive from the IIdentity and IPrincipal interfaces and overriding the application thread’s default identity. Please refer to the following blog post for more information an an example.
Custom authorization in WPF: https://blog.magnusmontin.net/2013/03/24/custom-authorization-in-wpf/
The actual credentials should be stored on some remote server that may be accessed through a web service, WCF service or some other kind of API. The details of how to actually get the credentails would be implemented in the AuthenticationService class in the sample code from the above link.

What is meant by Web Services?

Can anybody tell me what is meant by web services?
How do they work?
and more information about it.
Web services are typically application programming interfaces (API) or web APIs that can be accessed over a network, such as the Internet, and executed on a remote system hosting the requested services. --Wiki
Wiki has a good article on Web Services, you'll find a load of information there.
http://en.wikipedia.org/wiki/Web_service
As Andrew Tanenbaum and Maarten van Steen say in Distributed Systems - Principles and Paradigms, 2nd Edition: "a Web service is nothing but a traditional service (e.g., a naming service, a weather-reporting service, an electronic supplier, etc.) that is made available over the Internet". The main idea is that you have a client application that can use services provided (published) by a server application.
There are a couple of important things you should look into: one is the directory service which stores service descriptions, which should adhere to the UDDI standard. Another thing is that web services are described by the means of formal language (WSDL). And last, but not least, you need to specify how communication takes place: SOAP is a widely (probably most well-known) protocol in this sense.
Also, as can be noticed, be really careful about the standards (protocols, formal description language etc.), when implementing web services.
The ideas above have been taken from the aforementioned book (Distributed Systems - Principles and Paradigms, 2nd Edition, Andrew S. Tanenbaum, Maarten van Steen, 2007). For more programming language oriented books, you can check "Java Web Services: Up and Running" by Martin Kalin, O'Reilly, 2009 (did not read this but it is by a good publisher and it is new) and I am sure there are a lot of other good books out there.
Web services are just like a kind of framework, that you access over the Internet. That can be used for authentication, single sign-on, data access, etc. For instance, imagine a Twitter client. It can be a web application, a desktop application, or a mobile application. They all need to authentify a user, get the timeline, get the user tweets, and allow the user to post a new tweet. The aplication receives the data from the user, and transmit it to Twitter, by their web service. This is done by calling an URL on twitter.com with some parameters, depending on the web service format (soap, rest, etc). Then Twitter can process the action.
Web services allows applications to use, interact with, and communicate with other aplications. That way, you van have many apps, but only one data source.
Fahrenheit to Celsius - Simple Example Web Service (ASP.NET)
You can get started with Web Services # W3Schools.com.
Your first C# Web Service - Code Project
And most of your questions are answered in a 15seconds article.
in web application web-service used for transfer data using Ajax technologies without refreshing all page.
also i prefer to you this article with sample Create a JSON WebService in ASP.NET 2.0 with a jQuery Client link text wroted by Ajay Singh link text
If you are familiar with calling a subroutine (method/procedure/function/etc) with parameters and get a result back, then "web services" is one of many ways to call a subroutine located "elsewhere" and get a result back. "Elsewhere" is typically on another computer under the control of somebody else but you.
It has been tried several times before but I believe that Web Services have become so popular due to several reasons:
The communication can be done over http (like a browser). This means that a lot of infrastructure can be reused, and as http is simple, that infrastructure can be simple. This includes proxies, firewalls, debug tools etc.
Web Services include a "contract" - WSDL - saying exactly which things are provided, where they are, and what arguments they take, and what is returned. That contract allows building helping tools, proxies, creating a tool that simulates the other end, and much more.
Microsoft likes it. This results in good support on Windows, which gives many programmers an easy way in.
But, the answer to your question is "web services are subroutines located on other computers".
Web services are typically application programming interfaces (API) or web APIs that can be accessed over a network, such as the Internet, and executed on a remote system hosting the requested services. isma

WCF authentication service

I am relatively new to the WCF world so my applogies for the newbie question. I am currently designing a layer of WCF services. One of them is an authentication service, so I came up with the following authentication mechanism:
IUserService.TryAuthenticateUser(string username, string password, out string key)
Basicly the user tries to authenticate and if successful - he/she receives a sessionkey/securitykey/whateverkey... the key is then required for every other "WCF action" e.g.
IService.GiveMeMyFeatures(string key);
IService.Method1(string key);
This mechanism looks extremely intuitive for me and is also very easy to implement, so what bothers me is why I cant find similar WCF examples? This unique key (which is practically a session key with wcf-side expiration and all) can then by used from the various applications, according to the application's architecture: for ASP.NEt it can be stored in a cookie, for Winform/WPF/Mobile I guess it can be stored in the form-class in a field and so on...
So here comes question number 1: What do you think of this method?
I also read, that I can use the build-in ASP.NET Authentication Services (with membership providers etc... if I understood correctly). From architecture point of view I dont really like this method, because when authenticating from an ASP.NET page the workflow will be like this:
ASP.NET -> WCF -> ASP.NET Authentication Service -> Response
In this scenario one could also bypass the WCF layer and call the auth. service methods directly from the asp.net page. I know that by going thru the WCF layer for every authentication request I will lose some performance, but it is important for me to have a nice, layered architecture...
And here is question number 2: What are the advantages/disadvantages of this method over the first one, and why is it so popular, when from architecture point of view it is kinda wrong?
I also read, that I can send user credentials for every WCF method call and use the built-in mechanism to authenticate and respond properly to the request.
Q3: What do you think if this method?
And to sum up - obviously there are many authentication methods, but which one do you think is best and most generic (considering that the WCF services will be called from asp.net/wpf/mobile/etc...)?
Thanks is advance :)
The reason you can't find examples it's not best practice - it's turning something that should be stateless, web services, into something stateful, and something that will not load balance well at all.
As web services already have standard username and password facilities, supported by almost every SOAP stack (excluding Silverlight) that's the way to go. You can use the standard .NET role based security model to protect your methods with this approach as well.

Is there a WCF Rest C# Client Generation Tool?

Before I venture down the path of creating one, I was wondering if anyone knows of a utility program which will take the REST Help page of a WCF Rest Service and create the relevant Client for C# consumption.
Similar to what svcutil.exe does for WCF Services or what wsdl.exe did for web services but for WCF REST Services
Kind Regards,
Andrew
EDIT Some more detail:
Please see this link: http://msdn.microsoft.com/en-us/library/dd203052.aspx
In the restful service using the WCF Rest Starter Kit Preview 2, they supply types which will be serialized. But My intention is be able to create clients form the help page which describes schemas. Clients could then be created for C#, JavaScript, ActionScript etc.. shearly as a strongly typed version of the restful service, not a requirement or necessity. It is a program or uitlity I am wondering exists which does this
I think you might be looking for the WebChannelFactory. It can generate a channel class based on a WCF-attributed REST interface.
Well, there will not be any use even if you would like to abstract. ALL Rest services can use HTTP verbs like GET, POST, PUT, DELETE
So, basically what your client can have is only a static class which can accept the end point, network credentials, a name value collection which needs to be passed and the verb to use.
This would be more of a utility class rather than a client.
I don't remember seeing WSDL or some contract based on which we can write clients for the REST services.
I hope you don't spend too much time basing your code on the current help page of a pre-release piece of code. Are you even sure this help page provides all the information you would need to produce clients?
Also, have you seen Prerelease 2 of the WCF REST Starter kit yet? If no, go look. There's new client-side technology in there.
Why would you create clients for a RESTful service? You don't need one - you just need to be able to initial HTTP requests. If you would like to call the same operations via SOAP or some other method then create a new endpoint for the service and a new contract and expose mex for it so that svcutil can consume it.

Categories