Should i use httphandlers or web services? - wcf

I have a simple scenario where i want to output only json to the user.Now should i use a simple httphandler, call it from jquery and get the json or create a WCf service?
I want to use WCf service but don't see any advantage, maybe someone can point few of them and scenarios.

Anything would be suffice. Your thoughts are in correct direction, why to create a wcf service and increase the overload(maintaince, deployment etc).
If you are using Ajax, Look in to PageMethods, which would even free you from creating a separate HTTPHandler and you could call your code behind methods directly in your javascript.
I am assuming you are using asp.net.

Related

How do I create and Axis2 client

I've been given a WDSL file and have to create a web service client using axis2. I've been able to generate the CallbackHandler and Stub using WSDL2java. I've tried following this tutorial to create the Client http://briansjavablog.blogspot.com.au/2013/01/axis2-web-service-client-tutorial.html
I'm not sure if I implemented the client properly. It runs, but I'm not sure how you view any output results. I've never dealt with web services before. The Stub file that was generated contains so much code, how am I supposed to know what I should be calling? All tutorials I've found give example Clients, but I want to know what I need to look at to create my own.
If anyone has any advice or links to creating clients that are easy to understand, it would be appreciated.
I think that this probably went un-answered for a while due to the fact that the question is not clear and you probably need an introduction to Web Services and SOAP in general. If you are given the WSDL (or can pull it from a URL out there somewhere) then you are using the Web Service as a client - you have (from the post) already created the stub for client use. You simply need to use it. You are sending a request to the server (Web Service) and sending it the data that it requires (as the SOAP parameters that are laid out in the Web Service schema). Based on this SOAP request you will get a response. Your stubs that are created for the client act as the invocation and response points for your client.
So your question as to how do you test it: you decide what to do with the response as this is what you are coding into the client.
And about creating your own Web Service - you would need to start with a schema (often times you write your objects/data and the functions that you want them to perform and tools (like Axis2) will generate the server code (for Web Services and SOAP transport) on top of this.
So in your question, I think that you need to a) check out some Web Services books/online tutorials to figure out what it is, b) code your client to display the results and stuff - and just make sure that you are actually sending and getting responses from the Web Service, and c) also see what it would take to create your own Web Service (for whatever purpose you are planning the service to be established for, before creating your own.
Effectively I think that you just need to get your feet wet with Web Services in the first place. And the tutorial that you pointed out ( http://briansjavablog.blogspot.com.au/2013/01/axis2-web-service-client-tutorial.html) is excellent for anyone looking to get a web services client started - thanks for posting that.

How to route WCF REST services?

Was planning to use Service Routing (on WCF/REST) to do some common tasks before a request hits the actual service. Now that I read more about it, looks like REST is not supported yet on RoutingService and the suggested method is to use System.Web.Routing or ARR.
What needs to happen in the router is a key validation, a header value extraction and versioning.
ARR doesn't look right for this as it just routes and there is no "handler" we have access to. System.Web.Routing looks like a lot of custom implementation which might undermine the efficiency of WCF.
An old school alternative am thinking of is to have the common functionalities in one chain-of-responsibilities implementation and just compose it in every service. This has the disadvantage of being referenced in N number of places for N services. But this increasingly looks like the only alternative if I don't want to mess with the WCF handling of endpoints.
Am looking for advice on a right way to do this, and any samples.
Didn't try, but maybe writing a custom service behavior can solve your problem. Take a look here : Extending WCF with Custom Behaviors.
The idea is to extend the WCF engine with a custom behavior, then attaching your service with this behaviors. This is transparent for the services.
Take a look at HttpMessageHandlers in the new WCF Web Api project htttp://wcf.codeplex.com This mechanisms allows you to do something similar to Rack or WSGI. I have a couple of examples of what you can do with them on my blog http://www.bizcoder.com/index.php/2011/05/22/how-to-get-ahead-with-messagehandlers/

Implementing REST in WCF

I have a existing WCF in .NET which is consumed through wsdl and proxy classes. Soon, there will be multiple consumers and the load on the WCF will be pretty high. I was asked to develop a new WCF with REST which can be beneficial interms of performance. I don't have much knowledge on REST, hence can you please let me know whether implementing a RESTFUL WCF will improve the performance drastically? Please provide me any links to implement the same.
Thanks in advance,
Vinoth Khanna.S
You can also use WCF Data Services to easily offer a REST interface to your data.
The easiest way is to build an Entity Framework model of your data and then to expose that model as a WCF Data Service. This then exposes all data using the OData protocol, which is REST + AtomPub.
And Kiran is of course right, REST by itself does not increase performance. I assume that you want your UI to access the REST service directly rather than go through a web service which contains hand-written methods to read and write data. In that case, there may be some performance gain, but I wouldn't count on it much.
See also:
http://msdn.microsoft.com/en-us/library/cc668794.aspx
and
http://en.wikipedia.org/wiki/WCF_Data_Services
If you want to return results as JSON, the easiest way to get that to work is by adding the WCF Data Services Toolkit:
http://wcfdstoolkit.codeplex.com/
As far as I know REST is not for performance enhancement, it makes your webmethods URL accessible and make those URL's more predictable and logical. I would start with this video http://channel9.msdn.com/Events/PDC/PDC08/TL35 then with WCF REST Starter Kit http://www.asp.net/downloads/starter-kits/wcf-rest

Client Side Binding using by Converting the WCF Services to JSON

We have a Requirement of Consuming the WCf Services which is hosted in IIS like http://localhost/someservice.svc.
We would like to consume that Service via java script and bind my sample data controls called grid view on client side itself.
I think this can be done by Serializing and deserialzing to JSON and consume the data source and bind the grid controls.
Pls Refer the below link
http://forums.infragistics.com/forums/p/48035/258346.aspx
I would like to Achieve my func like the above link.
Can you pls guide me to achieve this Tasks.
Thanks
Regards
N.Balaji
Balaji,
Yes, you can definitely enable your WCF service (whether within IIS or not) to use JSON.
You do need to make one choice: do you want to use that service from the ASP .NET AJAX framework, or do you want to create a more general solution that is not tied down to that framework's usage within the browser?
If it's the former, use WebScriptEnablingBehavior. If it's the latter, use WebHttpBehavior.
For either scenario, detailed instructions are available in the following two MSDN sections:
AJAX Integration and JSON Support
WCF Web Http Programming Model

How to change default WCF page returned in browser?

The old ASP.NET ASMX Web services used to produce a Web page that allowed a user to navigate to the various methods and invoke them (as long as the parameters were all simple types).
WCF web services produce a much less useful page (You have created a service... blah, blah, blah...). My question is two part...
Can I get WCF to produce results like ASMX did?
OR
Can I produce custom HTML that documents my service? If so, How?
This service is a nice example of the kind of thing I'd like to do... http://footballpool.dataaccess.eu/data/info.wso
No, and no.
The service page that WCF produces is hard-wired, and I haven't ever heard of any trick or technique to change it. And no, you cannot get back the old ASMX service page, either.
There's a couple of things you can do:
based on your WSDL that completely describes your service, you could create an HTML help or man page (or pages) and have those displayed under a static URL (e.g. http://myserver/myservice/helppage.html)
you could create a totally separate page to describe your service, like the one you linked to, and make that available
Mind you: WCF services are by default SOAP based service calls - you cannot just call those from a web browser.