此问题未重复,请仔细阅读。收到HTTP响应时发生WCF错误
我有一个WCF服务和客户端,在同一个域上的不同机器上。 WCF服务具有以下几种操作合同:
[ServiceContract]
public interface IPatchService
{
[OperationContract]
List<PatchUpdateDTO> SearchForUpdates();
[OperationContract]
string InstallUpdates();
}
PatchUpdateDTO
类:
[Serializable]
[DataContract]
public class PatchUpdateDTO
{
[DataMember]
private string UpdateId { get; }
[DataMember]
private string Title { get; }
[DataMember]
private string Description { get; }
}
的请求监听的服务代码:
Uri baseAddress = new Uri("http://localhost:8000/PatchManagementService");
_selfHost = new ServiceHost(typeof(PatchService), baseAddress);
try
{
_selfHost.AddServiceEndpoint(typeof(IPatchService), new WSHttpBinding(), "PatchService");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
_selfHost.Description.Behaviors.Add(smb);
_selfHost.Open();
}
catch (CommunicationException ce)
{
...
}
我已经在我的客户端添加服务引用应用。
客户端代码:
public class AgentCommunicationWCFProvider : IAgentComminicationProvider
{
private readonly PatchServiceClient _patchManagementService;
public AgentCommunicationWCFProvider()
{
_patchManagementService = new PatchServiceClient();
}
public string InstallUpdates()
{
return _patchManagementService.InstallUpdates();
}
public List<PatchUpdateDTO> SearchForUpdates()
{
return _patchManagementService.SearchForUpdates();
}
}
客户端配置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IPatchService" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://someIpAddress:8000/PatchManagementService/PatchService"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPatchService"
contract="PatchManagementServiceReference.IPatchService" name="WSHttpBinding_IPatchService">
<identity>
<userPrincipalName value="****" />
</identity>
</endpoint>
</client>
</system.serviceModel>
现在一些奇怪的是发生,使用InstallUpdates()方法时,我得到一个返回字符串和它工作正常,但是当使用SearchForUpdates()方法时,假设返回List<PatchUpdateDTO>
,我得到以下错误:
附加信息:接收HTTP响应时发生错误 http:// someIpAddress:8000/PatchManagementService/PatchService。 这可能是由于服务端点绑定不使用HTTP协议。 这也可能是由于HTTP请求上下文被服务器 中止(可能是由于服务关闭)。查看服务器日志获取更多详细信
任何想法,为什么它有一个复杂的对象的问题?
摆脱[Serializable]属性并重试。你已经在类和属性上有了DataContract和DataMember属性,那么你为什么要在顶部使用[Serializable]?这个问题似乎在这个区域,因为InstallUpdates()只是回退一个WCF默认可以理解的字符串。 –
为什么您的PatchUpdateDTO类具有私有属性?他们应该是公开的。 –