WCF返回数据集,客户应用接收总出错,是配置有问题吗?

ice_frank 2008-05-18 05:39:17
请问,如果WCF service返回dataset数据集,配置上面是否要有特殊的配置?我的client应用,如果接受从WCF返回字符串是没问题的,但如果接收dataset就会报错:

接收对 DataAnalyzeService.svc 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。有关详细信息,请参阅服务器日志..........................................


=============================
这个返回数据集的方法可以肯定是可以返回数据集的。
现在不知道是个问题,请帮忙看看...
...全文
412 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
t20100504t 2010-07-21
  • 打赏
  • 举报
回复
学习了
lhzyn 2008-05-20
  • 打赏
  • 举报
回复
1 你的客户端使用SvcUtil.exe生成的代理?换成Channel试试。
2 传一个少量数据的DATASET试试。
3 用Stream传送Dataset试试
ice_frank 2008-05-20
  • 打赏
  • 举报
回复
@lhzyn

我是以添加service reference的形式添加的代理
这个System.Data.DataTable实际上只返回一个string数据

我认为返回数据集应该是可以,但不知道有那些地方没有注意到而导致这个问题?
lhzyn 2008-05-20
  • 打赏
  • 举报
回复
刚才在VS2008下做了个测试,
Server端代码如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.Data;

namespace DataSetInWCFService
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Press <ENTER> to start service.");
System.Console.ReadLine();
StartService();
Console.WriteLine("Serivce started.");

System.Console.WriteLine("Press <ENTER> to terminate service.");
System.Console.ReadLine();
StopService();
Console.WriteLine("Serivce stopped.");
}
static ServiceHost BNIIIBusinessDuplexServiceHost = null;
static void StartService()
{
BNIIIBusinessDuplexServiceHost = new ServiceHost(typeof(DataSetInWCFService.ServiceLib));
BNIIIBusinessDuplexServiceHost.Open();
}
static void StopService()
{
if (BNIIIBusinessDuplexServiceHost.State != CommunicationState.Closed)
{
BNIIIBusinessDuplexServiceHost.Close();
}
}
}
public class ServiceLib : DataSetInWCFService.IServiceLib
{
public DataSet GetDataSet()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("TestCol", typeof(string));
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
dr["TestCol"] = "SomeMessages";
dt.Rows.Add(dr);
ds.Tables.Add(dt);
return ds;
}
public string GetString()
{
return "SomeMessages";
}
}
[ServiceContract(Namespace = "http://DataSetInWCF/TestService")]
public interface IServiceLib
{
[OperationContract()]
System.Data.DataSet GetDataSet();
[OperationContract()]
string GetString();
}
}

配置如下

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior" name="DataSetInWCFService.ServiceLib">
<clear />
<endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
name="DataSetInWCFBHttp" contract="DataSetInWCFService.IServiceLib" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:3001/DataSetInWCF/TestService" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="NewBinding0" />
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>

客户端代码如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DataSetInWCFClient
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Press <ENTER> to start service.");
System.Console.ReadLine();
using (ServiceReference1.ServiceLibClient client = new DataSetInWCFClient.ServiceReference1.ServiceLibClient("DataSetInWCFBHttp"))
{
DataSet ds= client.GetDataSet();
Console.WriteLine(ds.Tables[0].Rows[0]["TestCol"] + "");
}
System.Console.ReadLine();
}
}
}

配置如下

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://localhost:3001/DataSetInWCF/TestService"
binding="basicHttpBinding"
contract="ServiceReference1.IServiceLib" name="DataSetInWCFBHttp" />
</client>
</system.serviceModel>
</configuration>


测试通过
wxg22526451 2008-05-20
  • 打赏
  • 举报
回复
UP
GengWH 2008-05-20
  • 打赏
  • 举报
回复
可能dataset的schema变了
不要传dataset,把数据分离出来单独传
LutzMark 2008-05-20
  • 打赏
  • 举报
回复
学习 帮顶
lhzyn 2008-05-20
  • 打赏
  • 举报
回复
你的Serivce中是不是还包含有其他方法,它们返回的是什么类型
service reference应该是基于ClientBase的代理,建议使用Channel调用Service。
我们曾经碰见过类似问题后来发现是客户端代理的问题,改用Channel就OK了。

ice_frank 2008-05-19
  • 打赏
  • 举报
回复
谢谢各位的提醒!

我传的是一个System.Data.DataTable,不知各位所说的Schema变化具体是什么意思?
如何解决这个问题,难道不能传这种数据吗?
ice_frank 2008-05-19
  • 打赏
  • 举报
回复
<GenericObjectDataSource DisplayName="DataTable" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>System.Data.DataTable, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</TypeInfo>
</GenericObjectDataSource>

但GenericObjectDataSource下显示:

"urn:schemas-microsoft-com:xml-msdatasource" element is not declared


不知是否这里有问题?
叶子 2008-05-19
  • 打赏
  • 举报
回复
友情up
bt_lose 2008-05-19
  • 打赏
  • 举报
回复
guanzhu
dsclub 2008-05-18
  • 打赏
  • 举报
回复
个人感觉,强类型的东西都很麻烦。

不要传DataSet,你的问题很有可能是Schema变化造成的
IamBM 2008-05-18
  • 打赏
  • 举报
回复
如果使用WCF,还是使用自定义实体类及泛型集合吧,DataSet太大,另外好像有Schema的问题(听别人说的,我很久没用DataSet了)。
蒋晟 版主 2008-05-18
  • 打赏
  • 举报
回复
可能dataset的schema变了
不要传dataset,把数据分离出来单独传

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧