Showing posts with label defined. Show all posts
Showing posts with label defined. Show all posts

Monday, March 26, 2012

Exposing Web Services defined in class libraries

I have a class library (or will have) that defines a bunch of web services. I can reference Atlas if necessary. How do I expose all these web services to Atlas via IIS/ASP.Net. In other words, I do *not* want the code for my web services to be in the web project, I want them to be in an external project and optimally just included with a single line for all services, or a line per service if necessary.

Thanks.

All you need to do is to add your assembly as a reference to the web project and then add it to the ScriptManager service reference as following:

 <atlas:ScriptManager ID="ScriptManager1" runat="server" > <Services> <atlas:ServiceReference Type="namepsace.typename" /> </Services></atlas:ScriptManager>

Replace the bold text with the type name of your web service.


Seems that this has changed since way back when... How do I reference a service in a class library now? How do I then hook it up to an extender, e.g. an AutoCompleteExtender?

Thanks.

Explorer Error: Sys is not defined

Hi,

I'm trying to create a profile to mantain the position of one panel. When this user open the web page this panel should be in the same position as before. I read the Atlas reference and copied the code of the examples, but the explorer returns me this error:

'Sys' is not defined.

Here is the code of my web.config file:

<microsoft.web>

<profileService enabled="true"

setProperties="PanelRelogTop;PanelRelogWidth"

getProperties="PanelRelogTop;PanelRelogWidth" />

</microsoft.web>

And here is the code I use:

<atlas:ProfileScriptService ID="pss1" runat="server"></atlas:ProfileScriptService>

<script type="text/javascript" language="JavaScript">

var PanelReloj = $("PanelReloj");

//This will load the profile data into the various HTML elements

//when the page loads.

function OnPageLoad() {

//Turn off automatic saving of the profile back to the server each time

//a profile property changes.

Sys.Profile.set_autoSave(false);

//Assign an event handler that runs once the profile has been loaded from the server

Sys.Profile.loaded.add(onProfileLoadComplete);

//Assign an event handler that runs once the profile has been successfully saved on the server

Sys.Profile.saved.add(onProfileSaveComplete);

//Load the profile from the server. As with all web service calls in "Atlas", the load

//occurs asynchronously.

Sys.Profile.load();

}

//Called when the profile data has been loaded from the server

function onProfileLoadComplete()

{

PanelReloj.top = Sys.Profile.properties.PanelRelogTop;

PanelReloj.width = Sys.Profile.properties.PanelRelogWidth;

}

function OnUpdateProfile()

{

Sys.Profile.properties.PanelRelogTop = PanelReloj.top;

Sys.Profile.properties.PanelRelogWidth = PanelReloj.width;

//Saves the profile on the server. The save occurs asynchronously.

Sys.Profile.save();

}

function onProfileSaveComplete() {

alert('The profile has been saved.');

}

</script>

Does anybody know if I'm doing something wrong or do I need to do something else?

Thanks!!!

When does OnPageLoad function gets called? Is it after Atlas has finished loading or when the window or body onload is fired? If it is the later case try removing the event handler and putting it in a javascript function called pageLoad (which gets fired when Atlas is loaded).

function pageLoad()
{
OnPageLoad();
}


It does on bdy onload event.

<body onload="OnPageLoad()">


Hi!

Instead of making your initial function call in <body onload=''> you should use the following snippet in the document:

 <script type="text/javascript"> function OnApplicationLoad() { MyFunc(); return false; } </script>

This is because the Ajax framework takes some time to initialize and your call is being made before the Sys object is created. The "OnApplicationLoad" is raised from Ajax when initialization is done.

--
Mattias Lindsj? | Fivestarday Sweden | www.fivestarday.se |


I think I solve the problem, I have to use Web object instead of Sys object. It's something I discover looking at the Atlas scripts or the object Browser on the Atlas reference.

Now, I do profile on web controls but only while the user is in the page. If the explorer is closed and then the user loads the same web page, there isn't values for the profile. I suppose after reading the documentation that these values are saved in some way and returned when the page is loaded again. How I do this using client code? And, what is the funcionality of the ProfileScriptService control?


hello.

if you're still using the Web namespace (instead of the Sys), then that means that you're running an old version of ATLAS (the March CTP is the latest release).

I've updated the new Atlas version and works fine with Sys object. Thanks for this point Luis.

Mattias, thanks for this code. It works with your suggestion and on the Load event of the body with the new version of Atlas.

Someone of you know how I can keep the profile for maintain configuration of pages?


I suggest starting a new thread with a descriptive title to focus on this. It's general best to limit one thread to a single issue, so that others can simply look at the title and know what it's about.

thanks,
David

Wednesday, March 21, 2012

Error; WebService Not Defined.

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.