I have use the TryUpdateModel method on the controllers but now I need to use it on a web service (.asmx).
Have anybody achieve this?
Thanks for your help...
The TryUpdateModel method is part of ASP.NET MVC. You cannot use it outside. In a web service you don't need it because usually requests and responses are serialized into objects automatically.
Related
I am working on web role in the Azure cloud service. Basically my web role is an MVC application and how can I make the controller in MVC communicate with the webrole.cs class. For example, in the run() method in webrole.cs I have received a message and I want to pass it to the MVC controller, how can I do that?
Any help is appreciated!
You'd better use a azure service bus queue to do that. Send a message on Run, and take the message from queue in your mvc app.
Scenario:
asp mvc application: WebSite. WCF service: Service, with DoSmth() method. I call Service from the WebSite.
What is the proper way to call Service.DoSmth()?
I can create it all time I need to use it, like this:
using (var service = new ServiceClient()) {
service.DoSmth();
}
Or I can add Service field to the controller class and create the Service in controller's constructor.
private Service service;
public MyController() {
service = new ServiceClient();
}
I want to know, whats the difference, regarding to sessions, because, if we create the Service in constructor, we create one long session. So what about session time-outs or something like this? And what are the benefits from the other points of views?
Another question is, where to call service.DoSmth()? I've read about mvc pattern, and I think, that the proper way due the pattern is to call it from models, because models should do the work, and controller is only a "manager", but I saw many examples, where people use models only like containers, to pass data from controller to view. So can somebody clarify it for me.
.
In many cases, you want to reuse the same WCF Client Proxy, as this connection method yields the best performance. Reusing the same proxy can be particularly beneficial if you use security features, which have a high initial security negotiation cost. Note: you surely need to check the state of the client proxy before using.
In the event that reusing the same client proxy is not an option, then consider using a ChannelFactory proxy that uses caching.
The following links provide good information and some guidance regarding best practices: http://blogs.msdn.com/b/wenlong/archive/2007/10/27/performance-improvement-of-wcf-client-proxy-creation-and-best-practices.aspx
http://msdn.microsoft.com/en-us/library/aa738757.aspx
I'm wondering if it's possible to service up WCF services via MVC. I've seen a few posts about this as it relates to RESTful services, but I'm not looking to create a RESTful service.
I've also seen this topic covered as far as serving up .svc files from MVC, but I'm not looking for that either.
Basically, I'm just looking to expose my WCF services via MVC, instead of a typical Wep App type structure with svc files.
so instead of having ttp://localhost/MyService.svc, I would just have ttp://localhost/MyService and that would go to a controller that would return the data.
Is it possible to have a "servicehost" controller? I would assume that the biggest obstacle to this would be that IIS handles the service a certain way based on the .svc extension - would some kind of custom handler have to be set up for something like this?
Any thoughts?
You can do this without MVC (or, it seems, with it too)
http://geekswithblogs.net/michelotti/archive/2010/08/21/restful-wcf-services-with-no-svc-file-and-no-config.aspx
http://geekswithblogs.net/michelotti/archive/2010/09/22/wcf-rest-services-inside-mvc-projects.aspx
I want to expose a service on my site that any users can call and get a JSON response. In the end, I want the users to be using this service as much as possible.
My site is created using the asp.net MVC framework and i was wondering whats the best way to do this...
I think most would say it's obvious to use a web service (*.asmx) that returns JSON format, but i know that I can just create a url that users can call and have it return JSON format as well (e.g: calling "http://mysite.com/GetList" would return JSON list). In asp.net, using the return Json() method.
What are the advantages/disadvantages doing it this way vs. a Web Service which is specifically intended for this ?
I don't know that most would say use a .asmx web service. Personally I haven't made a .asmx web service in a while and I would go for the MVC approach. The only things I'd be worried about would be:
future changes to the data, url, and/or parameters passed in.
Making the controller too big or cluttered, in which case you could create a separate API controller.
To me the advantages are that it's more consistent with the rest of your app, it's simple and easy to work with, and there's not much to configure.
A web service would expose a WSDL.
I have asp.net application which i am planning to convert into asp.net mvc app.
One area that i havn't found how it could be done is, App is using scriptmanager to make ajax calls to wcf service. And scriptmanager simply takes care or all element related to ajax, serializing - etc.
I haven't found what i can use in mvc that replaces that piece of functionality
Server hosting WCF service
MVC calling wcf service through ajax?
No controller, view etc to wrap wcf service to respond for ajax call
I found lot about using jquery, ajaxaction stuff but this don't look like exact replacement of scriptmanager like functionality.
If I understand your question, the easiest method would be to continue to use the ScriptManager control in the MVC port of the application.
The Polymorphic Podcast did a show on this topic. There are several potentially helpful links in the show notes.