此問題未重複,請仔細閱讀。收到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類具有私有屬性?他們應該是公開的。 –