Hi,
I realise this has been convered in other posts and on other websites I have found but the fixes suggested have not managed to fix my problem. I'm relativly new to implmenting Atlas so there is a high likelihood i've done something silly. I'll try and make my description of what ive done as comprehensive as possible.
My error is 'TestService' is undefined.
I'll start with the UI code. I am trying to create a web-service, which will be called when an HTML <select> element has its onChange event triggered.
// AddDoors.aspx ~ Javascript Trigger.
Response.Write("<select runat='server' class='select' name='woodAvail" + rsWoods["WoodID"] + "' onchange=\"javascript: testIt();\">");
Response.Write("<option value='unavail_" + rsWoods["WoodID"] + "'>Not Availible</option>");
Response.Write("<option value='avail_" + rsWoods["WoodID"] + "'>Availible</option>");
Simpe yes! Now, the Javascript function...
// AddDoors.aspx ~ Javascript function.
<script type="text/javascript">
function testIt()
{
TestService.HelloWorld(OnComplete);
}
function OnComplete(result)
{
alert(result);
}
</script>
The script manager...
// AddDoors.aspx ~ Atlas Script manager.
<atlas:ScriptManager runat="server" ID="script1" EnablePartialRendering="true">
<Services>
<atlas:ServiceReference Path="~/TestService.asmx" />
</Services>
</atlas:ScriptManager>
// TestService.asmx simply links to the code-behind file, which lives in the App_Code folder.
<%@dotnet.itags.org. WebService Language="C#" CodeBehind="~/App_Code/TestService.cs" Class="TestService" %>
// App_Code/TestService.cs ~ Web Service Code-Behind.
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TestService : System.Web.Services.WebService {
public TestService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World WS";
}
}
I have read on other threads and other forums that this problem can be often caused by the web.config file, so here is mine...
// web.config
http://endtable.net/paste/557b86d2.html
I have tried using PageMethods and writing the WebMethod within the AddDoors.aspx page, but this just gave the error PageMethods is undefined.
Again, sorry that this has already been covered in other threads but I just can't find a solution that works.
Thanks,
Dave.
Fixed it...
As I thought i'd missed something simple in the HttpHandlers in the web.config. For anyone with this problem, add the following block of code to your web.config.
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>
<!--
The MultiRequestHandler enables multiple requests to be handled in one
roundtrip to the server. Its use requires Full Trust.
-->
<add verb="*" path="atlasbatchcall.axd" type="Microsoft.Web.Services.MultiRequestHandler" validate="false"/>
<add verb="*" path="atlasglob.axd" type="Microsoft.Web.Globalization.GlobalizationHandler" validate="false"/>
<!--
The IFrameHandler enables a limited form of cross-domain calls to 'Atlas' web services.
This should only be enabled if you need this functionality and you're willing to expose
the data publicly on the Internet.
To use it, you will also need to add the attribute [WebOperation(true, ResponseFormatMode.Json, true)]
on the methods that you want to be called cross-domain.
This attribute is by default on any DataService's GetData method.
<add verb="*" path="iframecall.axd" type="Microsoft.Web.Services.IFrameHandler" validate="false"/>
-->
<add verb="*" path="*.asbx" type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>
</httpHandlers>
It lives within System.Web.
Cheers,
Dave.
In my web.config, those config codes existed, but while I run under iis server the error: webservice is undefined still existed.
I don't know how to fix. Any suggestions? Thanks!
Regards,
Nick.
No comments:
Post a Comment