CTICoder

A random spillage of programming (and other) thoughts

Annoying <Script> Tag Bug When Using Client-Side Web Services

Posted by Shaun McDonnell on August 11, 2008

This one took me hours to figure out and there is no rhyme or reason to it.  Yet, I have been able to reproduce it consistently so I thought I would share the details here.

Microsoft .NET 3.5 introduced a new Attribute called [ScriptService] that we can put at the top of our WCF Services or our ASMX Web Services.  The addition of this attribute to a service allows for that service to be called from the client-side of a web application using javascript.

 [ScriptService] public class Service : System.Web.Services.WebService 

Behind the scenes, .NET creates some javascript and it is automatically embedded in your code.  You can actually see the javascript it creates by just adding a ‘/js’ to the end of the ASMX url like this:

http://services.customers.ctiusa.com/cisco/ipphoneservice.asmx/js

If you want to use the client-side accessible web service from a pure HTML page (or something else that isn’t .NET) you can actually make a direct reference to that javascript path like this:

 <script language="javascript" src="http://services.customers.ctiusa.com/cisco/ipphoneservice.asmx/js" type="text/javascript">

However, this won’t work and the browser won’t be able to find the javascript reference.  Why?  Because it doesn’t like ‘/>’ for ending the script tag.  It wants the full ‘ ‘ like this:

 <script language="javascript" src="http://services.customers.ctiusa.com/cisco/ipphoneservice.asmx/js" type="text/javascript">  

Once you do that, you will be able to access your web service through pure asynchronous javascript calls.

-Shaun

 
Advertisements

One Response to “Annoying <Script> Tag Bug When Using Client-Side Web Services”

  1. Michael Bray said

    For an explanation of why, check out http://piecesofrakesh.blogspot.com/2005/03/script-tag-in-internet-explorer.html. Basic summary is that HTML is NOT XML, and in HTML, apparently the <tag /> format isn’t strictly valid, even though several browsers will interpret several of the tags correctly. Apparently, IE doesn’t interpret “correctly” (or incorrectly) for the <script> tag.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: