小编Mor*_*rat的帖子

"无法从传输连接读取数据:远程主机强行关闭现有连接

我使用Visual Studio 2010和MS SQL Server 2005.我是WCF的新手,我正在尝试学习开发一个小任务管理应用程序.

目前我有一个带有两个控制台应用程序的解决方案--WCF服务 - 连接到WCF服务的客户端以测试我的代码

WCF服务使用LINQ to SQL连接到数据库.我已经实现了一个OperationContract,它将一些内容插入到WCF服务后面的数据库中并且它可以工作.我已经实现了一个OperationContract,它将WCF服务中的GUID返回给客户端,并且也可以.

当我尝试从WCF服务检索List列表时,它失败并出现以下错误:

  • "收到对localhost:8000/TaskerTest/Service/operations的HTTP响应时发生错误.这可能是由于服务端点绑定不使用HTTP协议.这也可能是由于服务器中止了HTTP请求上下文

  • InnerException:基础连接已关闭:接收上发生意外错误.

我的合同(前两个工作.GetLists是问题):

[ServiceContract(Namespace = "http://Tasker_Server")]
public interface IOperations {
    [OperationContract]
    string CreateList(string listName, string text);
    [OperationContract]
    string UpdateList(int idList, string listName, string text);
    [OperationContract]
    List<ToDoList> GetLists();
}
Run Code Online (Sandbox Code Playgroud)

实施:

    public List<ToDoList> GetLists() {
        Guid token = OperationContext.Current.IncomingMessageHeaders.GetHeader<Guid>("token", "ns");
        int? userID = CheckCache(token);

        if (userID != null) {
            List<ToDoList> lst = DBAccess.GetListsByUserId(userID.Value);
            return lst;
        }
        else
            return null;
    }
Run Code Online (Sandbox Code Playgroud)

数据库访问代码:

     public static List<ToDoList> GetListsByUserId(int idCredential) {
        TaskerModelDataContext tmdc …
Run Code Online (Sandbox Code Playgroud)

wcf

8
推荐指数
1
解决办法
2万
查看次数

当它包含char数组时快速读取C结构

我有以下C结构

struct MyStruct {
    char chArray[96];
    __int64 offset;
    unsigned count;
}
Run Code Online (Sandbox Code Playgroud)

我现在有一堆用C语言创建的文件,里面有成千上万的结构.我需要使用C#读取它们,速度是一个问题.

我在C#中做了以下几点

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Size = 108)]
public struct PreIndexStruct {
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 96)]
    public string Key;
    public long Offset;
    public int Count;
}
Run Code Online (Sandbox Code Playgroud)

然后我用文件从文件中读取数据

using (BinaryReader br = new BinaryReader(
       new FileStream(pathToFile, FileMode.Open, FileAccess.Read, 
                      FileShare.Read, bufferSize))) 
{
    long length = br.BaseStream.Length;
    long position = 0;

    byte[] buff = new byte[structSize];
    GCHandle buffHandle = GCHandle.Alloc(buff, GCHandleType.Pinned);
    while (position < length) {
        br.Read(buff, 0, structSize);
        PreIndexStruct pis …
Run Code Online (Sandbox Code Playgroud)

c# performance struct unsafe c++-cli

8
推荐指数
1
解决办法
864
查看次数

WCF - 让客户选择返回格式

我正在尝试自己学习一些WCF.我有C#/ ASP.net知识,但我是WCF的新手.我在学习的过程中使用Visual Studio 2010来开发一些应用程序.

我开发了一个小型Web服务,它充当TODO /任务管理器的后端,用户可以在其中创建/删除/编辑新事件; 这一切都非常简单和基本.

我的问题如下:

  1. 有没有办法让客户选择他想要的返回格式(例如xml/json/rdf)而无需编写新的操作合同?
  2. 如何在客户端上看到Web服务发送给我的确切消息(以便我可以检查它是否是例如json表示或xml消息).

xml wcf json wcf-endpoint

7
推荐指数
2
解决办法
2142
查看次数

标签 统计

wcf ×2

c# ×1

c++-cli ×1

json ×1

performance ×1

struct ×1

unsafe ×1

wcf-endpoint ×1

xml ×1