Showing posts with label language. Show all posts
Showing posts with label language. 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 the value always is false?

Following is my codes. No matter I login or not,the userLoggedIn always be false. Why?

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" Codebehind="WebFormTest.aspx.cs" Inherits="EdtungWeb.WebFormTest" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title
<script language="javascript" type="text/javascript">
// <!CDATA[ function Test() { debugger var userLoggedIn = Sys.Services.AuthenticationService.get_isLoggedIn(); } // ]]> </script
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="Test()" />
<asp:Login ID="Login1" runat="server">
</asp:Login>
<asp:LoginStatus ID="LoginStatus1" runat="server" />
</form>
</body>
</html>

and the loginstatus is retrieving the right information?


Yes, it is, the loginstatus is retrieving the rightinformation.

Many thanks for your replying.

Unless you use the AuthenticationService to Login the user it will remain false. One hack might be to inject the following line in your pages from the server side when you are sure the user is logged in.
Sys.Services.AuthenticationService._authenticated = true;

I see.

Many thanks for your replying.


Would you mind marking that as answer.

Sorry for that.

Many thanks for your remind.