I've searched around and I can't find anything that shows how to consume a WCF webservice with Webmatrix using razor? I don't want to consume it with jQuery, I want to actually use the C#/razor syntax for that. Any ideas? Any help would be greatly appreciated!
Chris
If you're looking for something along the lines of "Add Service Reference" from Visual Studio, it isn't available in Web Matrix. You'll need to write all the plumbing by hand or use one of the Visual Studio Express products (http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express).
Related
I spent few days search on this case. I checked out all wcf asynchronous implementaions.
I wasn't able to find what I was looking for.
Below is scenario.
WCF is running to accept xml
WCF needs to response to user for success receiving xml and release
the request immediately
WCF then needs to do processing to save xml to database and parsing xml to
convert something else.
I don't want to use separate service to process above. I want to use one service to handle all 3 cases above.
I checked out asynchronous way of coding in WCF, but this doesn't release the request right away. What is the best practice for this? Is there any sample code I can use?
Thank you in advance.
I think you would be better suited to using a different technology. Maybe look at Windows Workflow Foundation.
You can host WCF Workflow Services the same way as you host a standard WCF service, the main difference is that you can create specific workflows that can continue after acknowledging receipt of the original message.
You do this by persisting the message and returning to the user. WF allows you to create actions that continue after sending response back to the caller.
Visual studio provides you with a design surface that allows you to drag and drop components to create custom workflows. Additionally you can also make calls to other services if required.
With .net 4.5 you can now use C#, in previous versions of WF you had to use VB.net.
You can read about it on the MSDN site here:
http://msdn.microsoft.com/en-us/vstudio/jj684582.aspx
Hope this helps
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
I have two dumb/rookie questions. My problem is, I have NO idea where to begin learning this stuff.
Traditionally, I am an ASP.NET developer. I am familiar with creating and consuming traditional web services (.asmx) in ASP.NET. Now, I want to create some REST based services that adhere to the HTTP verbs approach. I intend to use WCF services to accomplish this. In addition, I want to create my services like Twitter in a fashion where the caller can reference [serviceName].[xml|json]. Unfortunately, i do not know how to allow the caller to specific the format. It seems like I need to create two seperate services which seems odd. Am I way off? Can someone point me in the right direction?
Thank you!
Check this tutorial. It will show you how to create REST service in WCF. Part 4 of the tutorial will also show you how to create REST service which is able to return both JSON and XML response. Be aware that this is for .NET 4.0 which added a lot of features to REST API (including automatic response type).
Juval Lowy's 2nd edition on Programming WCF is available. This should be an excellent source; his first book was outstanding. Michele Leroux Bustamante is another excellent author on WCF, but her 2nd edition book isn't due for another few months, so go with Juval Lowy.
Essentially, WCF separates protocol (binding) from code, so you should be able to write the service once, and use multiple end points (address, binding, etc.) to provide different formats.
The Programming WCF book has a 3rd edition out now.
This article talks about consuming WCF services in Silverlight, but claims:
There will be no proxies, no generated code, no 3rd party utilities, and no disgusting "Add Service Reference" usage.
What is so wrong with me adding a service reference in my Silverlight project? Are there hidden overheads? Or is it a case of Fear Of Auto Magic on the part of the author?
The reasoning for that statement from the author appears to be:
To begin, let me start off by reminding everyone that you shouldn't ever use "Add Service Reference" in Visual Studio for magical service client creation. The code is incredibly verbose, hard to manageable, edits are prone to being overwritten, and it's almost always used as an excuse to not actually learn WCF. There are few things worse than having to deal with people who thing they know a product simply because they know how to use a mouse.
As someone who has relied on the "Add Service Reference" in Silverlight exclusively I think that is a bit over the top. I'd agree that the auto-generated code is verbose and it shouldn't be edited because it WILL be overwritten. However as far as manageability goes it doesn't get any simpler, in response to my service changing it takes one click to get the service reference back in sync.
Despite that I think the article is very good and I can vouch that the ease of adding service references has stopped me from delving deeply into WCF. That's not necessarily a bad thing as at the end of the day WCF is plumbing and I'm interested in writing my app not becoming a WCF expert. As it happens I have now reached a point where I am encountering some serialisation issues between Silverlight and my service which I suspect are related to the browser. I'll need to dig deeper into WCF to sort it out and that article looks like th perfect starting point.
The "Add Service Reference" has been fine for me for 1.5 years and while of course there are benefits to learning about the internals of WCF there is definitely nothing wrong with having a quick and simple point and click way to get started from within Visual Studio.
"Adding a service reference" in Silverlight has some problems right now...the config file gets regenerated each time the service is updated.
It goes a little further than the "auto magic" people are stressing as a problem. First, with a service reference you are "coupled" to the service and it's methods it exposes. If you re-generate the service the client has to do the same. Creating the service dynamically alleviates that problem. Furthermore, with abstraction/reflection/Dependency Injection you now have decoupled service references.
I don't think service references are bad, however WCF and web concepts are moving away from it. For example, WCF REST standards have no "service reference" that you consume...its just URL routing tables. More and more people are recommending this as a standard, for example Juwal Lowy (idesign.net and author of a couple WCF books) recommends not using service references as well.
When developing an application wich will be used inside an intranet do you think Silverlight and WCF is a good solution ?
Whould you use WCF Services or WCF Web Services to expose your model to the client ?
When consuming a WCF Service the proxies will be generated under a reference and you can only have 1 service reference per service, How can I have the application domain model created under the same service reference ?
Thanks.
A. Lampard.
Not yet. I had a difficult time getting WCF configured, and Silverlight 2 beta was not well documented.
Silverlight is out of Beta now, and compatibility with WPF has improved. If your skills are generally in .NET and you want a rich web application then Silverlight ought to be a no-brainer, especially on an intranet where you can reasonably guarantee everyone has Silverlight installed. Plus, it runs fine on Macs.
For services, WCF works with Silverlight and there are numerous examples of how they work together. Here's a video from the official site on that very subject:
http://silverlight.net/learn/learnvideo.aspx?video=47177
"Not sure if I understand your second question...not sure why would you want more than 1 reference per service...?"
When you have, for example, a ProductService wich uses the classes Product and Family, if you create the proxies for this service you'll get: ServiceReference1.Family and ServiceReference1.Product. Now supose you create the FamilyService, when consuming this service you'll get the Family proxy created again, but under ServiceReference2 !
Your questions is way too broad. It's really hard to answer these kinds of questions, since, really, "any" technology is good for "any" solution. Otherwise everybody would just use one!
What's your application supposed to do, how soon you need to get it done, is there any existing investment in the same or other technologies...etc.?
Having said that, to answer your question: yes.
Not sure if I understand your second question... not sure why would you want more than one reference per service...?