Ajax error calling Web Service from Web Application Project vs Web Site

I am implementing the code from the Asp.Net Ajax Video Demo “How Do I: Make Client-Side Network Callbacks with ASP.NET AJAX?”  The Web page is generating a javascript error (‘SimpleService’ is undefined) and is unable to recognize the Web service.  The downloaded examples work, however I have created the Demo (both the page and the web service) in a Web Application Project, rather than a Web Site.  The demo uses a Web site.  Because of this the page does not recognize the Web service. 

To ask the question another way: What needs to be done differently in a Web Service in a Web Application Project (vs. a Web Site) to ensure the Service can be referenced and accessed via the pages javascript.  Or is there a reason why this cannot be done? 
 I am new to Ajax and Web services, so I apologize for my Newbie question.  Thanks in advance. (Edit: Code did not post correctly, sorry) <head runat="server">   
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
<!--
function Button1_onclick()
{   
ret = SimpleService.SayHello(document.getElementById('Text1').value, OnComplete, OnTimeOut, OnError);   
return (true);
}
function OnComplete(arg) {   
alert(arg);
}
function OnTimeOut(arg) {
}
function OnError(arg) {
}
// -->
</script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Services><asp:ServiceReference Path="SimpleService.asmx" /></Services>
        </asp:ScriptManager>
        <div>
            <input id="Text1" style="width: 240px" type="text" />&nbsp;
            <input id="Button1" type="button" value="Say Hello" onclick="return Button1_onclick()" />
        </div>
    </form></body></html>
''Web Service as created in Web Application Project (AjaxTestApp1/SimpleService.aspx.vb>
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _<ToolboxItem(False)> _
Public Class SimpleService
    Inherits System.Web.Services.WebService   
    <WebMethod()> _
    Public Function SayHello(ByVal name As String) As String
        Return String.Format("Hello: {0}", name)
    End Function
End Class

'
'Web Service as created in Web Application Project (HDI-AJAX-NetworkCalls-VB/App_Code/SimpleService.aspx.vb)
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class SimpleService
    Inherits System.Web.Services.WebService
 
   <WebMethod()> _
    Public Function SayHello(ByVal Name As String) As String
       Return "Hello : " + Name
    End Function
End Class

 


David Williams MCP
.Net Senior Developer
0
dwilliams459
6/14/2007 10:17:04 PM
asp.net.networking-webservices 2181 articles. 0 followers. Follow

1 Replies
1418 Views

Similar Articles

[PageSpeed] 20


It appears that I needed to reference the Web Service using the Project name in addition to the actual service name from javascript. I discovered this by looking at the Javascript as generated by the Webservice.  For example: Javascript on the aspx page was calling the service with the following:

function Button1_onclick() {
  ret = SimpleService.SayHello(document.getElementById... )
}

However I should have referenced the web service using

  ret = AjaxTestApp1.SimpleService.SayHello(document.getElementById... )

I discovered this by downloading and opening the the "proxy" javascript generated by the Web service through http://localhost:49646/SimpleService.asmx/js.  This file provides the reference to to the service to be called from javascript.  I was able to see I needed to include the Project name when calling the service. 

AjaxTestApp1.SimpleService.SayHello= function(name, ... )


David Williams MCP
.Net Senior Developer
0
dwilliams459
6/15/2007 2:49:34 PM
Reply:

Similar Artilces:

Ajax call web services failed after convert web site into web project
Hi Guys I have one web site application and use ajax call web services. it is working very well. 1. Master page set up scriptmanager with webservices path. 2. Web service inside web site application under app_code named ajaxwebservice.cs 3. Javascript call ret=ajaxwebservice.method(id, oncomplete(),ontimeout(),onerror()); But after I convert web site into web application project, the ret=ajaxwebservice.method(id, oncomplete(),ontimeout(),onerror()); failed, the ajaxwebservice in undifined error. I use the same web.config, master page, I put my ajaxwebservice.asmx and ajaxwebservic...

Converting web site project to web application in vs 2008
I am converting web site project into web applicatio project in vs 2008 and running into web reference related issue.  I am not so sure how to address this.  Our old web site application had app_webreferences folder with AllServices as sub folder and then all of the web services under that folder. for example:  AllServices\AService.wsdl  AllServices\BService.wsdl   AllServices\CService.wsdl   etc... our code references AllServices.BService in the code or AllServices.AService etc...  It seems like when I Right Clicked on web application project...

Creating Web Service
Hello everyone, I am creating a new web service, and was wondering what you all thought the advantages and disadvantages of creating it using a Web Site vs using a Web Application Project...thoughts?  Is one better than the other in terms of deployment?  Is one better for development and debugging? Thanks! Hi d_helland, To understand which one is prefer to your situation, please read the following two articles. What's New in Web Projectshttp://msdn2.microsoft.com/en-us/library/f7fb46ye(VS.80).aspx Introduction to Web Application Projectshttp://msdn2.microsoft.com/en...

web app vs web site vs web project
Could someone describe the differences between web sites, web apps and web projects? (or send me a link that contains this comparison?). Is one of these terms synonomous with another? What are the advantages/disadvantages of each?  How does one choose when starting new development? Can one type be converted into another?     Thank you. Here is my definition: Website: perspective of users. Collection of web pages.Webapp and project: perspective of developer (and webmasters). Collection of web pages and resouces (database, code, etc.). Maybe software installers...

Converting Web Site to Web Application (AJAX web service goes missing)
I have just completed (almost) an exercise to convert a web site to a web app (acedemic reasons - just to see the differences).A few bumps on the road such as copying class files to the new solution and wondering for a while why the classes did not show up.  It was because the properties for the class file were "content" rather than "compile".  Also copied all my images to a newly created image folder outside the IDE.  There is no context menu item to refresh a folder in the Web App so it was out of the car and back in to fix that.One problem remains. ...

Web Application Projects vs. Web Site Project- Where is Copy Project?
I have opted to use the Web App Project in 2005 (The 2003 Model)http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspxWhy is the copy project missing when this model is used? It was there in 2003?Thank you,Patrick http://www.SURFThru.com   SURFThru.com I wanted to bump this topic again to see if any Microsoft techs had any input on this item.SURFThru.com...

Web Site Project: How to configure web service URL in web.config (web service defined in a referenced DLL)
I have a web site that references a business logic DLL project. In the business logic project, there is a web service defined in its app.config file something like this: <applicationSettings>  <MyNamespace.BLL.Properties.Settings>    <setting name="MyNamespace_BLL_MyServer_ServiceName" serializeAs="String">    <value>http://blah.blah.blah.asmx</value>  </setting>  </MyNamespace.BLL.Properties.Settings></applicationSettings> When the web site is published, the web ...

VS 2005 SP1 + .NET AJAX => automatically adds web.config in nested Web Application Project when opening project or solution
I get a 'Configuration Error' on an aspx page because VS added automatically a web.config to my nested Web Application Project where no web.config file should be. This effect I have noticed since I have installed SP1 and .NET AJAX Extensions. Why is VS 2005 adding the web.config file and how can I disable this behavior? Following is the content of the automatically added web.config file (comments omitted): <?xml version="1.0"?><configuration>    <appSettings/>    <connectionStrings/>    <system.web> &...

Conversion Error while converting from VS 2005 web site to Web application project
Hi all, I am trying to convert to WAP from Website VS 2005. I get the following error Error 3 Type 'frmXXX' already defines a member called 'Page_Load' with the same parameter types  I dont understand the error.Does this mean it compiling twice? Unable to research because of the vagueness of the error.   I followed the steps below 1) Move all the .aspx and *.cs files in new web application folder 2) Right click and convert to web application 3) rebuild the project. After following the steps above i get the error mentioned in the email   P...

Calling web services from Web application projects
Hi, I have a web service. So I add ScriptManager and register that service. Then I add a block of javascript. Intellisense shows me that my service is recognized and when I write a script and run it it works. But If I do the same but not in "website" but in "web application project", intellisense doesn`t recognize it and that same script fails runtime because my webservice is undefined. What can I do with it? ThanksIf this is a answer to your problem, mark it as answer in right upper corner. It helps other who read your article to known that it is correct answer  ...

Which is best web application projects or Web site projects in VS 2008
Hi, Using VS.NET 2008 We are developing a web based product (inventory, accounts,etc). This product has DA, BO layers. We are currently using web site project model. We are using webdelopyemnt project for deploying at client place.I want to know that, which model Web site model or web applicaton model is a best model for applications?I read most of the blogs and also articles for knowing difference between these two models.  But I am not coming under conclusion.Let me know your views and alos best answers Regards S. Muhilan   As you probably know, the difference between...

Web Site VS Web Application Project?
Hi,   I am heading up a project to help develop standards for development in asp.net 2.0 at my company (2 years late) and would like to hear some advice from the forum, from developers with experince on using VS2005, specifically about the topic of Web Site VS Web Application Project.   It seems that the Web Site is what is being pushed? Does Microsoft plan to eliminate the Web Application Project eventually? We have come to the decision that the Web Application Project is the right choice for upgrading existing projects but what is everyone using ...

web application project VS Web site
When I have to create a new website in VS I normally  go to the File Menu and then select new website.But when I create a web application project and when I click on the properties of that I see so many options like for Build: Platform target, Errors and Warnings.why i don't see these properties in normal web site. Also where is all this setting info about the web application project is stored? Is it even important to mention the platform target like X86, X64, ItaniumThanks.   hi, just mention the source where u want to store, when u r creating a project and that project...

Cannot call a web service from java script using ajax in .net 3.5 web applications
As like 2005 .net websites i tried to consume a web service from client side java script  using Ajax script manager in  .net 3.5 (2008) version web application it was not working, Event it works with 3.5 web sites, What i have to do to solve the issue. Thanks in advance Hi, can you create the least amount of code to reproduce it and post it? This gives us the ability to check out your code and better guide you. Also please check out this article: Create a Simple WCF Web Service and Use In JavaScript With Visual Studio 2008 and .Net 3.5.  Grz, Kris.Read my blog. Handy Fire...

Web resources about - Ajax error calling Web Service from Web Application Project vs Web Site - asp.net.networking-webservices

Application - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

The Bachelor 2016 application process can get explicit - Laurina Fleure
CHANNEL Ten is calling on singles to sign up for a chance to find love on The Bachelor , but willing applicants have to open a lot more than ...

Would you give up chocolate for better application performance?
Application performance is critical to business performance according to 98 percent of businesses, yet 89 percent of executives say the poor ...

Gun Sales, Concealed Permit Applications Surge After San Bernardino
The day after Syed Farook and Tashfeen Malik opened fire in San Bernardino, gun sales and concealed carry permit applications surged.

MBA: Mortgage Applications Increase in Latest MBA Weekly Survey, Purchase Applications up 29% YoY
From the MBA: Mortgage Applications Increase in Latest MBA Weekly Survey Mortgage applications increased 1.2 percent from one week earlier, ...

Falling Costs, Rising Applications Will Boost US Energy Storage Market
... in 2013 to 3,659MWh by 2020 on improving economics and policy developments, predicted GTM Research's Shayle Kann Falling Costs, Rising Applications ...

Mortgage applications down 0.2%
Mortgage interest rates haven't moved much in the past three weeks, but they are holding at a higher level than for all of 2015.

California Film & TV Tax Credits Applications Dip In New Small Screen Round
With production on the uptick in the home of Hollywood , the second round of those seeking small screen Golden State tax credits saw 32 applications ...

Digitimes Research: China touch panel makers increasing investments in niche products and large-size ...
The China International Touchscreen Exhibition (C-Touch) was recently held in Shenzhen, China, featuring a number of local and international ...

Six internet-of-things applications in big new government trial
Manchester, England, is set to be the UK demonstrator city for internet-of-things innovation. Of course, there is much smart technology already ...

Resources last updated: 12/10/2015 6:15:32 PM