C# - Call A Web Service From The Controller?
Jun 17, 2010I have an asp.net MVC2 application that needs to call a web service from the controller. How do I do this? It is a RESTful service that returns Json data.
View 4 RepliesI have an asp.net MVC2 application that needs to call a web service from the controller. How do I do this? It is a RESTful service that returns Json data.
View 4 RepliesI did some service operation in mywcfdataservice.svc Now I have to use the service operation in my controller but I don't find them.I can use:
Entities2Voice context = new Entities2Voice();
and so I can read the table of my db, but I didn't find the way to see sevice operation.I have my model.edmx to use sql db and the code in mywcfdataservice.svc works right. I can call the service operations from my browser and they work.I try to add service reference to my .svc file, to use it as a service, but when I press ok button after some seconds, I take an error (is in Italian):Il documento HTML non contiene informazioni per l'individuazione del servizio Web.I metadati contengono un riferimento che non può essere risolto: 'http://localhost:2873/WcfDataService2Voice.svc'.Il tipo di contenuto text/html; charset=utf-8 del messaggio di risposta non corrisponde al tipo di contenuto del binding (application/soap+xml; charset=utf-8). Se si utilizza un codificatore standard, verificare che il metodo IsContentTypeSupported sia implementato
correttamente. I primi 1024 byte della risposta erano: '
How to call Synchronous service call for combo boxes? As I know Synchronous calls do not create a good user experience because the application is hung waiting for the Web service call to return. Then it is my requirement.
View 1 Replieswhether its possible to call an web service on a private corporate network from a web service located in a dmz?
View 2 Repliesi have created a normal web service and i want to host it outside IIS. one idea i got is to use window service as hosting environment. i have created a web service and hosted it window service and its window service is running now.would anybody please let me know that how can i call web service hosted in window service binded over soap.tcp. here is my sample code.
[Code]....
[Code]....
I have one problem with actionlink. My Example is: i have one view and controller named as XYZ.aspx and XYZ.vb controller , in this view i put below line
<%=Html.ActionLink("Manage", "Index", "Advertisement", New With {.aintCampaignid = Cam.CampaignID})%>
I have another view and controller named as Index.aspx and Advertisement.vb if click on manage link in XYZ view it will call to advertisement controller and index function But iam getting [URL], it wont call ..
how to page index.cshtml call variable from controller
i using vs2010 & mvc3.0
application has a main controller which gets some requests that should be filtered first. This main controller decides which other controller should handle the request.The redirection is usually possible with RedirectToAction(..). But using this method causes a round trip and changes the original called url. This behaviour is not wanted. The url should e left as it was in the origin request.Is this possible? If yes - how?If i instanciate a controller myself (simple call of new MyConstructor()) and call the wanted action then this controller runs in the wrong context and the views won't be found.
View 8 RepliesI want to create a base web project which other projects will extend. How can i call the render action on the controller found in the base controller?
View 1 RepliesCan I call a webservice from a Controller Action in ASP.Net MVC?
public ActionResult Index()
{
PersonObject person = new Person("Sam");
//Call a webservice which is located in the same app under /Services/General.asmx/WebMethod and pass it person
}
Basically I want to do this from my Action...
$.ajax({
type: "POST",
url: "/Services/General.asmx/WebMethod",
data: JSON.stringify(DTOInternetPricing),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(res) {
},
error: function(res) {
}
});
I'm working on getting a new MVC 3.0 application up and running on a Windows 2008 server, running SQL05 and IIS7 with ASP.NET Framwork 4.0 as well as MVC installed. The index page has two select boxes. Selecting an option in the first select box does an ajax call to my controller that populatest the second select box. This works just fine on my winxp dev machine but returns a 404 on the call to the controller when running
on the server. Code for that call:
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("CamperDirectory", "TradingPost")) { %>
Select a Season: <%: Html.DropDownListFor(x => x.SelectedSeason, new SelectList(Model.GetSeasons, "Value", "Text"),"Please select a Season.") %><br /><br />
<%: Html.ValidationMessageFor(model => model.SelectedSeason)%>
Select a Session: <%: Html.DropDownListFor(y => y.SelectedSession, new SelectList(Model.GetSessions, "Value", "Text"), "Please select a Summercamp Session.") %>
<%: Html.ValidationMessageFor(model => model.SelectedSession)%>
<input type="submit" value="Go" />
<% } %>
</asp:Content>
<asp:content ID="Content3" contentplaceholderid="HeadContent" runat="server">
<script language="javascript" type="text/javascript">...............................
How do I call and action/controller from inside a jquery function?
View 3 RepliesI have one problem with actionlink. My Example is: i have one view(xyz.aspx) and controller(abc.vb) , in this view i put below line
<%=Html.ActionLink("Manage", "Index", "Advertisement", New With {.aintCampaignid = Cam.CampaignID})%>
I have another view(Index.aspx) and controller(Advertisement.vb) if click on manage link in XYZ view it will call to advertisement controller and index function But iam getting [URL] it wont call.
i have an ascx page and it contain certain methods... on click i want to make a jquery ajax call to the controller and call the ascx page methods..
View 3 RepliesAs I call the Controller to exit the focus of my textbox? I need to exit the textbox, go to the database to get information that will supplement the information from my form.
View 2 RepliesI have a mvc controller that communicates with a we service for user authentication, when user clicks login button, onclick event makes a call to javascript function using ajax and it makes a call to an action in server.The problem is when a use fiddler tool shows ajax call to the controller and also web service call, web service is called from controller never javascrit, how I can protect visibility of web service calling?, using web forms with the same scenario never shows a web service call.
View 2 RepliesThis is probably something simple. The following JQuery call is executing and calling the controller. The controller is executing correctly. I used the sample data that's commented out to verify that the templates were working also. However, the success function is not executing in the browser. Any thoughts or other ways I can debug this?
<script type="text/javascript">$(document).ready( function(){ alert("Here"); @* var myData = [ {first: "Jane", last: "Doe"}, {first: "John", last: "Doe"} ]; *@ $.getJSON( "/User/Filter",function(myData){ $("#myDataTemplate").tmpl(myData).appendTo("#itemContainer"); } ); alert("there"); }
);</script>
//Controller
public ActionResult Filter() { var myData = this.repository.GetAllUsers(); //return Json(myData); return Json(myData, JsonRequestBehavior.AllowGet);}
In the view I have a HTML button:
<input type="submit" value="Submit" />
Also I have a dropdownlist, how do I call the controller's action after I click the "Submit" button?
And how do I pass the Model back to the controller action as well?
The reason I want to pass back the model (or other object/class) to controller's action is I might have 5 dropdown lists and 3 edit boxes values to be sent as parameters. So I would like to assign these parameters into a object and send it back to controller's action.
ia ma working on an asp.net mvc 2 app and i have a Users view, displaying all the users of the database. Then, i would like to add the ablility to display "users starting with fisrt name" capabaility on the same view. For this i created a list of all english leters that actually are links (<a href="#">A</a>, etc...)
I managed to handle the click event of each one of the letters and get the corresponding letter via jquery, but i don't know how to call theHttp.Post Users/FindUserByFirstLetterName(string letter) on the click event.
I cannot use the Html.ActionLink<> helper, since it redirects me to the HttpGet controller action.
I also tried using using jqery.Post but i also couldn't manage to call the action.
I'm trying to write a controller method that returns an ActionResult.
In this method, i would like to:
1. call an HTML helper method
2. Capture and store the HTML helper's rendered HTML in a string
3. Return the method with the rendered HTML wrapped as a JSON
How do i call the Html Helper method from my controller method? Simply using the static class HtmlHelper does not work.
i would like to call an HttpGet GetEvents(Datetime dateSelected) controller action each time the user cliks on a date in jquery ui datepicker. I handle the onSelect datepicker event in order to call GetEvents() and refresh the Events page with the events for the selected date. The $.ajax method i use from jquery hits the GetEvents action, but instead of refreshing the page (and the url), i get an ajax result back.
[Code]....
So, how could i just call the HttpGet GetEvents() controller action via jquery, without the use of ajax in order to refresh the page?
I am quite new to MVC development and facing some basic issues.
I am having a form on which I am taking input form user. It is bould to one of the properties on Model class.
I am having a submit button
<input type="submit" value="Save"/>
Now I want to call Save Action in my controller on click on this Save button.
But it is not working. I have checked on following things:
1. My HTML page is correctly point to the controller
2. I have written HTML code as
<%= HTML.BeginForm("Save","ControllerName", FormMethod.Post); %>
<input type="submit" value="Save"/>
<%= HTML.EndForm();%>
I know we can set autopostback property of dropdwonlist using javascript or jquery and it will go to action controller specified in Form tag.
[Code]....
but how can we set it to some different action other then what we specified in Form Tag.
I am working on Tenant module that has to display following fileds, Tenant Id, Tenant Desc, Contact Person, Contact Phone. In the DB, these are designed as two separate tables - Tenant and Contact. Tenant table has Tenant Id, tenant Desc and Contact Id . Contact table has all the contact related properties. I am using EF as DAL.
To make my system loosely coupled, I have created a repository pattern to talk to EF entities. Also, for validation I am using service layer.
My repository layer has two interfaces and classes corresponding to Tenant and Contact.
public interface ITenantRepository : IRepository<Tenant> // IRepository<T> is a generic interface for CRUD operations
{
Tenant Get(int id);
IEnumerable<Tenanr> List() ;
[Code]....
i have a website where i provicde a link. On clicking the link a controller action method is called to generate a zip file after creation of zip file is done, i show the link to download the zip file by replacing the link to create a zip with the link to download the zip.
the problem is that after zip file creation is over and link is shown, when user clicks on the link to download the zip file, they are sent to login. After providing correct credentials in the login page they are prompted to download the zip file. they sould not be sent to the login page. In the action to generate zip file i haven't abondoned the session or haven't not done anything that abondons the session.
the user should not be sen't to login page after successful creation of zip file user should be able to download the file without login. i search internet on this problem, but i did not find any solution. In one of the blog written by hanselman i found this statement that creates the problem with the session: Is some other thing like an Ajax call or IE's Content Advisor simultaneously hitting the default page or login page and causing a race condition that calls Session.Abandon? (It's happened before!)
so i thought there might be some problem with ajax call that causes the session to expire, but i don't know what is happening? it's like this after users click on the link to create zip file the zip file is created successfully but the session gets expired. this is not what i want. Why does the session has to get expired after making a jquery post call to controller action to create a zip file? i hope u understand the problem.