【发布时间】:2009-04-30 17:39:35
【问题描述】:
我在我的服务器 here 上有这段代码(是的,我知道 ASMX 是个坏主意,但由于某种原因 WCF 根本不起作用):
<%@ WebService Language="C#" Class="Test" %>
using System.Web;
using System.Web.Services;
[WebService(Namespace = "http://smplsite.com/smplAccess")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Test : System.Web.Services.WebService
{
State s;
public Test()
{
s = (Session["foo"] ?? (Session["foo"] = new State())) as State ;
}
[WebMethod(EnableSession = true)]
public void Set(int j) { i=j; }
[WebMethod(EnableSession = true)]
public int Get() { return i; }
}
class State
{
public int i = 5;
}
当我运行以下代码时:
class Program
{
static void Main(string[] args)
{
var ser = new ServiceReference1.TestSoapClient();
Console.WriteLine(ser.Get());
ser.Set(3);
Console.WriteLine(ser.Get());
}
}
我希望能回来:
5
3
但我回来了
5
5
我的解决方案
- 使用
wsdl.exe生成代理类 - 根据需要添加引用以使其编译
- 使用Martin's解决方案
编辑:添加状态对象。
【问题讨论】:
-
我强烈建议您尝试让 WCF“Hello, world”服务正常工作,然后尝试找出为什么您的 WCF 版本的这个“根本不工作”。这将是坚持使用 ASMX 的一个不好的理由。
-
@John:WCF hello world 在我的系统上运行。在我的服务器上尝试相同的代码失败,并且与技术支持人员交谈表明 WCF 被正式禁止。
标签: asp.net web-services asmx