Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Wednesday, March 28, 2012

Why my web services cant accept parameter?

When my javascript call the echoString(s) in the following code, it return nothing

<%@dotnet.itags.org. WebService Language="C#" Class="WebService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {

[WebMethod]
public string echoString(string s) {
return s;
}

}

The strange things are my .NET program works fine with the code above and my javascript client program doesn't work with the code above but works fine with other people's web services. EX:

http://www.mssoapinterop.org/asmx/simple.asmx?op=echoString

What is wrong with my code? Thank you!!!!!!!!!

asdpai:

what is wrong with my code?

nothing, code is correct. Decorate youre WebService with theSystem.Web.Script.Services.ScriptService() and the WebMethode with the ScriptMethod() attribute eg.

<%@. WebService Language="C#" Class="WebService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
usingSystem.Web.Script.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService()]
public class WebService : System.Web.Services.WebService {

[ScriptMethode()]
[WebMethod]
public string echoString(string s) {
return s;
}

}

Hope that coul help.

why script enabled webservice making postback to server?

My WebPage has two textbox & one button.On button click I call script enabled webservice asynchronously still why my page go for postback to server?

<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="page2.aspx.cs"Inherits="page2" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

<scriptlanguage="javascript"type="text/javascript">

<!--

function Button1_onclick()

{

ret= WebService.Hello(document.getElementById('TextBox1').value,OnComplete,OnTimeOut,OnError);

return(true);

}

function OnComplete(args)

{

document.getElementById('TextBox2').value=args;

}

function OnTimeOut(args)

{

alert('Timeout');

}

function OnError(args)

{

alert('error');

}

// -->

</script>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>

<asp:ButtonID="Button1"runat="server"Text="Button"OnClientClick="Button1_onclick();"/>

<asp:TextBoxID="TextBox2"runat="server"></asp:TextBox>

<asp:ScriptManagerID="ScriptManager1"runat="server">

<Services>

<asp:ServiceReferencePath="WebService.asmx"/>

</Services>

</asp:ScriptManager>

</div>

</form>

</body>

</html>

===============================================

WebService

using System;

using System.Web;

using System.Collections;

using System.Web.Services;

using System.Web.Services.Protocols;

///<summary>

/// Summary description for WebService

///</summary>

[WebService(Namespace ="http://tempuri.org/")]

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService()]

publicclassWebService : System.Web.Services.WebService {

public WebService () {

//Uncomment the following line if using designed components

//InitializeComponent();

}

[WebMethod]

publicstring Hello(string msg) {

return"Hello"+msg;

}

}

function Button1_onclick()

{

ret= WebService.Hello(document.getElementById('TextBox1').value,OnComplete,OnTimeOut,OnError);

return false; // return(true); you need to return false instead of true. if you return false it doesn't do post back.

}

Thanks,

Kiran


Still same condition it does post back.I tried same application with HTML controls textboxes & button it works fine but when I tried with server side control it posts back


Hi,

can you post code that you used for testing.

Thanks,

Kiran


here is code with HTML textboxes & button for same script enabled webservice

<%@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

<scriptlanguage="javascript"type="text/javascript">

<!--

function Button1_onclick()

{

ret= WebService.Hello(document.getElementById('Text1').value,OnComplete,OnTimeOut,OnError);return(true);

}

function OnComplete(args)

{

document.getElementById('Text2').innerText=args;

}

function OnTimeOut(args)

{

alert('Timeout');

}

function OnError(args)

{

alert('error');

}

// -->

</script> </head>

<body>

<formid="form1"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server">

<Services>

<asp:ServiceReferencePath="WebService.asmx"/>

</Services>

</asp:ScriptManager>

<div>

<inputid="Text2"type="text"/>

<inputid="Text1"type="text"/>

<inputid="Button1"type="button"value="button"language="javascript"onclick="return Button1_onclick()"/>

</div>

</form> </body>

</html>


Hi,

function Button1_onclick() still returns true.

did you change it to return false. and tried it.

Thanks,

Kiran


yeah.......I did change it to false & tested it ,it does post back .The code which I posted doesn't postback but its withHTML control which works fine & I am trying to do same webservice code but with server control.

Hi,

can you change below code

<asp:ButtonID="Button1"runat="server"Text="Button"OnClientClick="Button1_onclick();"/>

to

<asp:ButtonID="Button1"runat="server"Text="Button"OnClientClick="return Button1_onclick();"/>

make sure that function is called. keep alert message in Button1_onclick function so you know that function got invoked when you click Button1_onclick.

Thanks,

Kiran


Thank you Kiran it works just fine.But I didn't get difference b/nButton1_onclick() & return Button1_onclick() could you please explain it?

Thanks

Manisha.


event = "return function()" if function returns false the event gets canceled.

if your case we are forcefully canceling onclick event by returning false.

event = "function()" doesn't matter what function returns.

Thanks,

Kiran

Monday, March 26, 2012

Wilcos ProgressBar Demo

I've been looking overWilco's ProgressBar demo and fixed it up to work with the current version of ATLAS. It's running and I can call methods on the control doing the updating of the progress info, but I can't get the timer to fire on it.

Looking over the code I can't find anything wrong with - the interval is set and assigned to the timer, but the timer simply isn't firing - I see nothing with Fiddler and the internal onTimerTick event is never actually hit.

I have been testing the control with a little bit of JavaScript code to fire the timer and that works fine, but I can't seem to get the internal timer to fire and ping back to the Web Service. Anybody have any idea, why the timer isn't firing in the below code?

I'm hooking things up through code rather than using XmlScript for now.

+++ Rick --

<scripttype="text/javascript">

Sys.UI.ProgressBar =function(associatedElement) {

Sys.UI.ProgressBar.initializeBase(this, [associatedElement]);

this.element = associatedElement;

var _timer =new Sys.Timer();

var _progress = 0;

var _showPercentage =true;

var _serviceURL;

var _serviceMethod;

var _responsePending;

var _tickHandler;

this.get_progress =function() {

return _progress;

}

this.set_progress =function(value) {

if (value >= 100) {

_timer.set_enabled(false);

}

_progress = value;

this.element.style.width = value.toString() +"%";

if (_showPercentage && value > 5)

this.element.innerHTML = value +"% ";

}

this.set_showPercentage =function(value) {

_showPercentage = value;

}

this.get_showPercentage =function() {

return _showPercentage;

}

this.get_interval =function() {

return _timer.get_interval();

}

this.set_interval =function(value) {

_timer.set_interval(value);

}

this.get_serviceURL =function() {

return _serviceURL;

}

this.set_serviceURL =function(value) {

_serviceURL = value;

}

this.get_serviceMethod =function() {

return _serviceMethod;

}

this.set_serviceMethod =function(value) {

_serviceMethod = value;

}

this.getDescriptor =function() {

var td = Sys.UI.ProgressBar.callBaseMethod(this,'getDescriptor');

td.addProperty('interval', Number);

td.addProperty('progress', Number);

td.addProperty('serviceURL', String);

td.addProperty('serviceMethod', String);

td.addMethod('start');

td.addMethod('stop');

return td;

}

this.initialize =function() {

Sys.UI.ProgressBar.callBaseMethod(this,'initialize');

_tickHandler = Function.createDelegate(this,this._onTimerTick);

_timer.tick.add(_tickHandler);

this.set_progress(0);

}

this.dispose =function() {

if (_timer) {

_timer.tick.remove(_tickHandler);

_tickHandler =null;

_timer.dispose();

}

_timer =null;

Sys.UI.ProgressBar.callBaseMethod(this,'dispose');

}

this.start =function() {

_timer.set_enabled(true);

}

this.stop =function() {

_timer.set_enabled(false);

}

this._onTimerTick =function(sender, eventArgs) {

alert('timer tick');

if (!_responsePending) {

_responsePending =true;

Sys.Net.ServiceMethodRequest.callMethod(_serviceURL, _serviceMethod,null, _onMethodComplete,null,null, [this]);

}

}

function _onMethodComplete(result, response, context) {

var behavior = context[0];

behavior.set_progress(result);

_responsePending =false;

}

}

Type.registerSealedClass('Sys.UI.ProgressBar', Sys.UI.Control);

Sys.TypeDescriptor.addType('script','progressBar', Sys.UI.ProgressBar);

</script>

<scripttype="text/javascript">

var Progress =new Sys.UI.ProgressBar($('ProgressBar'));

function ShowProgress()

{

SimpleService.InitializeProgressInfo(0);

Progress.set_interval(2000);

Progress.set_serviceURL("atlas/simpleservice.asmx");

Progress.set_serviceMethod("ProgressInfo");

Progress.start();

Progress.set_progress(5);

//StartProcessing();

}

function StartProcessing()

{

SimpleService.ProgressInfo(-1,StartProcessingCallback);

}

function StartProcessingCallback(Result)

{

Progress.set_progress(Result);

if (Result < 100)

window.setTimeout('StartProcessing();',1000);

}

</script>

Duh...

The code is missing a call to Initialize() to start the timer and other initialization going. It seems kinda silly that Initialize() isn't called automatically when in construct the object.

The progress stuff works, but I can't get the Web Service stuff to work - the ServiceMethodRequest object has changed and no longer supports calling the Web Service with simple parameters.

If anybody has any idea on that that'd be great.

The docs still suck - without knowing what parameters mean they're not terribly useful.

+++ Rick --


The way you invoke service methods has changed a little. The new signature looks like this:

invoke = function(url, methodName, params, onMethodComplete, onMethodTimeout, onMethodError, onMethodAborted, userContext, timeoutInterval, priority, useGetMethod)

Therefore, you should try to change

'Sys.Net.ServiceMethodRequest.callMethod(_serviceURL, _serviceMethod, null, _onMethodComplete, null, null, [this]);'

into

'Sys.Net.ServiceMethod.invoke(_serviceURL, _serviceMethod, null, _onMethodComplete, null, null, null, [this]);'

Hey! This is just what I need, but how do I set the whole thing ablaze? I've created an upload page, which works fine. And I have a webservice which, based on the client IP, returns the current status of the process.

I've put the javascript progressbar directly in the aspx file, a div (class="progressBar") within a div (class="progressBarContainer") and the stylesheet classes from Wilcob's example. Furthermore I've set the serviceUrl to my webservice, and the servicemethod to my servicemethod.

When I run the page, the process runs thrugh just fine and uploads files, but I get an error on the page (in IE) refering to this line (marked with:*):

this

.set_progress =function(value)

{

*if (value >= 100)

{

_timer.set_enabled(

false);

}

_progress = value;

this.element.style.width = value.toString() +"%";if (_showPercentage && value > 5)this.element.innerHTML = value +"% ";

}

I've put the Initialize() in there like this:

Sys.UI.ProgressBar =

function(associatedElement)

{

Sys.UI.ProgressBar.initializeBase(

this, [associatedElement]);this.element = associatedElement;var _timer =new Sys.Timer();var _progress = 0;var _showPercentage =true;var _serviceURL;var _serviceMethod;var _responsePending;var _tickHandler;

_timer.Initialize()

And I've changed the Sys.Net.ServiceMethodRequest.callMethod as WilcoB mentioned above.

Any idea? Please help..

Saturday, March 24, 2012

working with Asynchoronous Call back Events

Hiiii,

I want to Implement some Asnynchoronous call back events along with some regular postback event.Please Help me..

Regards,

Harsha

Hi

Search more about synchonus and asynchronus postback triggers


http://ajax.asp.net/docs/overview/AsynchronousLayerOverview.aspx

Would this be practical?

I was thinking it might be nice to have a search user screen which in the background uses a webservice to call out and retrieve a list of users from the db and use the autocomplete method I have seen used before - I'm not worried about security its just would this by using atlas to do this would this be a reasonable thing to do?

hello.

well, you could do that if you have a web service that returns that info...