所以我的问题很像这个:WCF service: Returning custom objects,但是,尽管该问题中有解决方案,但我看不到任何工作。
昨天我提出了一个与此相关的问题,但如果没有确定我的问题的潜在来源,我已经接近了。
我不认为我正在使用的数据大小有问题。我可以将此数据发送到服务器,但我在检索它时遇到了问题。我正在返回一个名为ProjectDetails
over的对象WCF
。但是,我遇到了从服务接收到客户端的问题。
是否有我遗漏的设置,或者有没有一种方法我WCF
错误地配置了我的课程?
这是我的ProjectDetails
代码:
[DataContract]
public class ProjectDetails
{
[DataMember]
public int projectId { get; set; }
[DataMember]
public string name { get; set; }
[DataMember]
public int calYearId { get; set; }
[DataMember]
public string projectState { get; set; }
[DataMember]
public string reportTitle { get; set; }
[DataMember]
public int plantId { get; set; }
[DataMember]
public string holdNumber { get; set; }
[DataMember]
public string holdDescription { get; set; }
[DataMember]
public string remarks { get; set; }
[DataMember]
public string adminComments {get; set; }
[DataMember]
public int companyId { get; set; }
[DataMember]
public int customerId { get; set; }
[DataMember]
public string folderNumber { get; set; }
[DataMember]
public int invoicedInFull { get; set; }
[DataMember]
public int approved { get; set; }
}
这是我的服务合同中定义的方式:
[ServiceContract]
public interface IProjectService
{
[OperationContract]
ProjectDetails GetProjectDetails(int selected_id);
}
我已经重新生成了我的代理svcutil.exe
并更新了我的服务参考。但是,每次我调用该GetProjectDetails
方法时,我的代码都会失败。我得到:
底层连接已关闭:接收时发生意外错误。
请,如果有人可以提供帮助,我将不胜感激。
更新
客户端配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IProjectService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://192.168.0.99:9000/ProjectService/ProjectService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProjectService"
contract="IProjectService" name="BasicHttpBinding_IProjectService" />
</client>
</system.serviceModel>
</configuration>
客户端配置:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="ProjectBaseWCFServiceLib.Service1Behavior" name="ProjectBaseWCFServiceLib.ProjectService">
<endpoint address="" binding="basicHttpBinding" contract="ProjectBaseWCFServiceLib.IProjectService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/ProjectBaseWCFServiceLib/Service1/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ProjectBaseWCFServiceLib.Service1Behavior">
<!-- 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 -->
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
客户端代码:
Console.WriteLine("Testing................");
ProjectBaseWCFServiceLib.ProjectDetails details = client.GetProjectDetails(1);
Console.WriteLine(details.adminComments);
Console.WriteLine(details.approved);
Console.WriteLine(details.calYearId);
Console.WriteLine(details.companyId);
Console.WriteLine(details.folderNumber);
Console.WriteLine(details.holdDescription);
Console.WriteLine(details.holdNumber);
Console.WriteLine(details.invoicedInFull);
Console.WriteLine(details.name);
Console.WriteLine(details.plantId);
Console.WriteLine(details.projectId);
Console.WriteLine(details.projectState);
Console.WriteLine(details.remarks);
Console.WriteLine(details.reportTitle);