简体   繁体   English

从Wcf服务连接到dbml

[英]Connecting to dbml from Wcf service

I have Web application and android application which are communicating with Wcf Services. 我有与Wcf Services通信的Web应用程序和android应用程序。 One of my Service is Chat.svc 我的服务之一是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);
}

and Chat.svc.cs 和Chat.svc.cs

  public StartChatResult StartChat(StartChatEntity sce)
    {
        //doing something else

        List<tblChatRoom> list = ChatManager.GetChatRoomList();

        return new StartChatResult() { IsSuccess = true, ChatRooms = list };

    }

And this method from my ChatManager class 而这个方法来自我的ChatManager类

public static List<tblChatRoom> GetChatRoomList()
    {
        SessionDBDataContext db = new SessionDBDataContext();
        return db.tblChatRooms.ToList();
    }

When i call StartChat method from Android side, always having a "Bad Request" response. 当我从Android端调用StartChat方法时,始终会出现“错误请求”响应。 When i taking comment this line 当我对此行发表评论时

List<tblChatRoom> list = ChatManager.GetChatRoomList();

i'm having "Ok", no problem. 我有“确定”,没问题。 There is a problem in this line. 这条线有问题。 Also SessionDBDataContext class is 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>();
        }
    }
}

I think there is a problem with SessionDB.dbml but when i use a method which is not service method to have Chatroom list, it is ok. 我认为SessionDB.dbml存在问题,但是当我使用不是服务方法的方法来拥有Chatroom列表时,就可以了。 I could not understand what is wrong when calling in service. 致电服务时,我不明白怎么了。 pls help 请帮助

test this code: Create a class such as tblChatRoom, for example: 测试此代码:创建一个诸如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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM