English 中文(简体)
Wcf 服务连接到 dbml
原标题:Connecting to dbml from Wcf service

I have Web application and android application which are communicating with Wcf Services. One of my Service is 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 和Chat.svc.cs 和Chat.svc.cs 和Chat.svc.cs 和Chat.svc.cs 和Chat.cs 和Chat.svc.cs

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

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

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

    }

而这方法来自我的聊天管理者班

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

当我从Android一侧打电话给 StartChat 方法时, 总是有一个“ 错误请求” 的响应。 当我评论这条线时

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

i m having "Ok", no problem. There is a problem in this line. Also SessionDBDataContext class is

[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>();
        }
    }
}

我认为会话 DB.dbml 有问题, 但如果我使用非服务方法的方法来编制聊天室列表, 也没关系 。 我无法理解在服务中调用时有什么不对 。 pls help

问题回答

test this code: Create a class such as tblChatRoom, for example:

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 };

}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签