SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software Kodyaz Development Resources
Development resources, articles, tutorials, code samples and tools and downloads for ASP.Net, SQL Server, R Script, Windows, Windows Phone, AWS, SAP HANA and ABAP, like SAP UI5, Screen Personas, etc.

Software Development



Exposing .NET Web Services to Client Script using Microsoft AJAX and using Inline Script property

Hello,

I want to share with you a small piece of knowledge which I found it tricky about exposing .NET web services for use from client side javascript codes.

You know if you are developing AJAX enabled web pages in your web projects, it is very simple to make .NET web services enable for consume of client side javascript method calls.

All you have to do is adding a Script Manager object in your web page and giving the path of the web service you have published as ServiceReference in the ScriptManager object.

ServiceReference in ScriptManager object will enable the code, actually the methods you have created in the web service .asmx page to be available for use from client-side scripts.

If you have implemented such a solution for your web project, you might have experienced the case that the javascript source file can not be downloaded by the client browser just because of the application shield, firewall or protection applications filtering the request and eliminating the request for the javascript file just because of the url path is not a very common file address.

In such a case where the javascript file produced by the server side application is not downloadable the application will fail as you have desired.

When you reference a .NET web service the client browser will make request to the server for the javascript file as using a url address like "http://www.kodyaz.com/client-enabled-web-service-sample.asmx/js". This syntax I mean using the servicename.asmx/js is very like making a request for listing a web folder. Some applications may block such requests.

In such a case you may use just adding the InlineScript="true" option configuration setting in the ServiceReference element. The default value for InlineScript is false. A "true" value for InlineScript will enable embedding the required javascript code block within the web page itself. In this case a seperate javascript file is useless and will not be created. Instead the contents of the javascript code file will be placed in the .aspx file itself. This javascript statements will include the necessary javascript methods for an AJAX web service method call. Since the browser will not make a request for a url like sample-client-web-service.asmx/js file, the applications will not block the requests and the client will successfully run and render the AJAX enabled aspx files that are making web method calls from client-side.

Setting the InlineScript option to TRUE will increase the size of the web page, and will not let using a downloaded and shared javascript file, it may increase the overall request bandwidth. But for our case we have experienced today, using InlineScript=true saved our day!

Published Thursday, August 21, 2008 10:00 PM
Filed Under: ,

Comments

No Comments
Anonymous comments are disabled

About eralper

SQL Server administrator and T-SQL developer including BI components Web programming with HTML, HTML5 and ASP, ASP.NET and .NET Framework developer SAP ABAP and SAPUI5 development, Web Dynpro and Smart Form Siemens HiPath Center CTI development
Copyright © 2004 - 2020 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems