[英]Connecting to dbml from Wcf service
我有與Wcf Services通信的Web應用程序和android應用程序。 我的服務之一是Chat.svc
[ServiceContract(Namespace = "http://webchat.com")]
public interface IChat
{
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "Start")]
StartChatResult StartChat(StartChatEntity sce);
}
和Chat.svc.cs
public StartChatResult StartChat(StartChatEntity sce)
{
//doing something else
List<tblChatRoom> list = ChatManager.GetChatRoomList();
return new StartChatResult() { IsSuccess = true, ChatRooms = list };
}
而這個方法來自我的ChatManager類
public static List<tblChatRoom> GetChatRoomList()
{
SessionDBDataContext db = new SessionDBDataContext();
return db.tblChatRooms.ToList();
}
當我從Android端調用StartChat方法時,始終會出現“錯誤請求”響應。 當我對此行發表評論時
List<tblChatRoom> list = ChatManager.GetChatRoomList();
我有“確定”,沒問題。 這條線有問題。 SessionDBDataContext類也是
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="SessionDB")]
public partial class SessionDBDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
public SessionDBDataContext() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["SessionDBConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}
public SessionDBDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public SessionDBDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public SessionDBDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public SessionDBDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public System.Data.Linq.Table<tblChatRoom> tblChatRooms
{
get
{
return this.GetTable<tblChatRoom>();
}
}
public System.Data.Linq.Table<tblTalker> tblTalkers
{
get
{
return this.GetTable<tblTalker>();
}
}
public System.Data.Linq.Table<tblSession> tblSessions
{
get
{
return this.GetTable<tblSession>();
}
}
public System.Data.Linq.Table<tblMessagePool> tblMessagePools
{
get
{
return this.GetTable<tblMessagePool>();
}
}
}
我認為SessionDB.dbml存在問題,但是當我使用不是服務方法的方法來擁有Chatroom列表時,就可以了。 致電服務時,我不明白怎么了。 請幫助
測試此代碼:創建一個諸如tblChatRoom的類,例如:
public class ChatRoom
{
public string username;
public string firstname;
public string lastname;
public ChatRoom(){}
public ChatRoom(string username, string firstname, string lastname)
{
this.username = username;
this.lastname = lastname;
this.firstname = firstname;
}
}
public StartChatResult StartChat(StartChatEntity sce)
{
//doing something else
List<ChatRoom> list =
(from q in ChatManager.GetChatRoomList()
select new ChatRoom(q.username, q.firstname, q.lastname)).ToList();
return new StartChatResult() { IsSuccess = true, ChatRooms = list };
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.