Posts

Showing posts with the label Webservice

Donate

AngularJS $http service returns html instead of JSON string

Good day! I've been trying to consume an ASP.NET Web Method using AngularJS $http service and all I get from the response is the html page source instead of string data. After investigating and doing some searching, the workaround is to set the responseType to json and pass an empty data to the Web Method given that the Web Method has no parameter. var myapp = angular.module( 'myApp' , []); myapp.controller( 'ctrl' , function ($scope, $http) { $http({ url: "63MakeAjaxCallAndReturnJSONWebService.aspx/HelloWorld" , dataType: 'json' , method: "POST" , responseType: 'json' , data: {}, headers: { "Content-Type" : "application/json;" } }).then( function (response) { $scope.value = response.data.d; }); }); And also declare the Web Method as static. [WebMethod()] public static string HelloWorld() { return "Hello World!" ; }

The type specified in the TypeName property of ObjectDataSource 'ObjectDataSource1' could not be found (ASP.NET Webservice)

As I was updating one of my ASP.NET Web Forms application to 4.5, running the app generates an error as stated above. I remembered that the Object Datasource control was dependent on a webservice. So, after reviewing the new configuration of the webservice, the port, url and namespace have changed. So, here are the steps to make my app work again. Steps: 1. Update the web service .discomap file through Add Service Reference and then choosing advanced to target it as .NET 2.0 platorm. Though Service Reference should be recommended or WCF service. 2. Change Web.Config setting of the web service including it's IP and Port. Example:<br> <add key="localhost.ECommerceService" value="http://192.168.2.1:1448/WebDeployServer/QuotesPaymentService.asmx"/><br> to<br><add key="localhost.ECommerceService" value="http://192.168.2.1:14070/WebDeployServer/QuotesPaymentService.asmx"/> 3. Configure again the obje

WebService Is Undefined Error In ASP.NET 4.0

1. First step is to add reference to the web service using Ajax Script Manager: <asp:ScriptManager ID= "ajaxManager" runat= "server" > <Services> <asp:ServiceReference Path= "~/Services/ProductService.asmx" /> </Services> </asp:ScriptManager> 2. Secondly is to include the namespace in calling the webservice method From ProductService.GetProducts( function (data) { $.each(data, function (index, elem) { $( "<option />" ) .text(elem.ProductName) .val(elem.ProductID) .appendTo( "#products" ); }); } ); To AccessingServerSideDataUsingClientScript.Services.ProductService.GetProducts( function (data) { $.each(data, function (index, elem) { $( "<option />" )

Clean Invalid XML Characters In C#

Here's a cool way to clean Large XML files with invalid xml characters. Note: Stream from is the original xml file, while Stream to is the new xml file with invalid characters removed. private void Copy(Stream from , Stream to) { TextReader reader = new StreamReader( from ); TextWriter writer = new StreamWriter(to); writer.WriteLine(CleanInvalidXmlChars(reader.ReadToEnd())); writer.Flush(); } public static string CleanInvalidXmlChars( string text) { string re = @"[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000-x10FFFF]" ; return Regex.Replace(text, re, "" ); } Source: http://social.msdn.microsoft.com/Forums/ Post: Invalid character returned from webservice

Using Sessions In ASP.NET Web Forms Web Services

Lately, i was confronted with a problem on managing state with web services, after reading a book on XML in .NET 2.0, i found a tip on creating and consuming web services with state capabilities. I followed this link: Using Session State in a Webservice MSDN: Web Service Session This idea, is a life saver to some of my web projects.. :D

Format Width Of AutocompleteExtender AjaxControlToolkit

By default, the width of the autocomplete list of autocomplete extender is inherited from the target control which is the textbox. However, you can customize the width and appearance of the ajax control: 1. Create an asp.net website 2. Add a webservice to your site 3. In your webservice, add a code to retrieve customer or any info. 4. In your asp.net website, add an aspx markup similar below:  Note that CompletionListElementID target control is the div called autocomplete declared below the textbox. <asp:ToolkitScriptManager ID= "ToolkitScriptManager1" runat= "server" > <Services> <asp:ServiceReference Path= "~/YourSampleService.asmx" /> </Services> </asp:ToolkitScriptManager> <div> <table> <tr> <td><asp:TextBox ID= "txtName" runat= "server" ></asp:TextBox></td> <td><div id= "AutoComplete" runat= "server&q

Donate