【发布时间】:2015-04-30 11:41:25
【问题描述】:
我创建了一个 WCF 服务并想测试我使用 WCF 测试客户端添加的一种方法。当我最初创建该方法时,它返回了一个 DataTable。当我使用 WCF 测试客户端添加服务时,该服务是使用原始 app.config 文件添加的。返回 DataTable 的方法显示一个“X”,因为我了解到您不能返回此数据类型。所以我创建了一个包含 DataTable 的类。 DataContract,Subject,由该方法返回。代码如下:
[ServiceContract]
public interface IPaging
{
[OperationContract]
Subject GetSubjectList(string strUserID);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
}
[DataContract]
public class Subject
{
DataTable dtSubjectData = new DataTable();
[DataMember]
public DataTable SubjectTable
{
get;
set;
}
}
方法详情: 命名空间分页服务 { 公共类分页:IPaging { 主题 cSubject = new Subject();
public Subject GetSubjectList(string strUserID)
{
....
}
}
}
现在,当我尝试将服务添加到 WCF 测试客户端时,我收到错误消息: “无法访问服务元数据。” 这是我的 app.config 文件:
<system.serviceModel>
<services>
<service name="PagingService.Paging" behaviorConfiguration="SimpleServiceBehavior">
<endpoint address="" binding="wsHttpBinding" contract="PagingService.IPaging">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/PagingService/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="SimpleServiceBehavior">
<serviceMetadata httpGetEnabled="True" />
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
在我看来,它与 app.config 文件无关,因为当方法返回 DataTable 时,原始条目有效。但是现在返回类型现在是“主题”,它没有在某处更新。
当您更改方法签名时,是否还有其他需要更改的地方我错过了?
谢谢。
【问题讨论】:
标签: c# .net web-services wcf datatable