您的位置:首页 > 其它

sliverlight: The remote server returned an error: NotFound.

2010-04-21 16:56 453 查看

.Background

I want to use the session in sliverlight, so I create wcf set Session and get Session.

why use the wcf operate the session? because the sliverlight don't support the session .

.phenomenon

I create the wcf

1)add the" <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>" in web.config.

2) modify the services class " [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]"

3)add namespace "System.web" to project. Now you can use the httpcontext.current.seesion .

4) I add two method in service class (getSession and setSession) , code is here:

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class LoginService
{
[OperationContract]

public Member Login(string UserName, string Passwrod)
{
Hashtable ht = new Hashtable();
ht.Add("@Login_Name", UserName);
ht.Add("@PWD", Passwrod);
DataTable dt = SQLHelper.getDataTable("sp_Login", ht);
if (dt != null && dt.Rows.Count > 0)
{
Member m = new Member();
m.UserName = dt.Rows[0]["Login_Name"].ToString();
m.ID = dt.Rows[0]["Ref_No"].ToString();
m.TeamID = dt.Rows[0]["Team_ID"].ToString();
m.Role = dt.Rows[0]["Role_ID"].ToString();
SetObjectToSession("User", m as object);
return m;
}
return null;
}
[OperationContract]
public void SetObjectToSession(string name,object value)
{
HttpContext.Current.Session.Add(name, value);
}
[OperationContract]
[ServiceKnownType(typeof(Member))]
public object    GetSessionObject(string key)
{
return HttpContext.Current.Session[key];
}


when I call login function ,I will save the member data to the session. this logic is right.

but another page getSession that throw the "The remote server returned an error: NotFound".

I am so grief, I search the resources that explain the server side or client side have error setting.

I think this error it is the client side don't know what type return. because I return object don't member data.

but I set the session is member data.

.solution

I modify the getSession function return the member data ,this problem have fixed.

why the wcf don't know convert the object to member ? my function cann't hardcode member type.

I think use the serviceknowtype will fix this problem ,so I try is ok.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐