C#:如何从WCF响应获取标头?

时间:2018-07-17 10:01:30

标签: c# wcf

我尝试从C#访问第三方WCF服务。它具有一个登录方法,该方法仅返回true或false作为结果,但是如果登录成功,它将返回一个cookie(使用“ Set-Cookie”标头)。

如何获取Cookie?我发现无法访问完整回复。我可以附加处理程序吗?消息拦截器仅显示消息,不显示标题。

到目前为止的代码:

var binding = new System.ServiceModel.NetHttpBinding(System.ServiceModel.BasicHttpSecurityMode.Transport);
var address = new System.ServiceModel.EndpointAddress("https://host.com/service/webservice.svc");
var svc = new WebSvc.ServiceHostClient(binding, address);     
var res = svc.Login("username", Base64Encode("secret"));

res是否成功登录=>如何从响应中获取cookie?

1 个答案:

答案 0 :(得分:0)

应使用客户端消息检查器(MSDN)。

您需要检查reply方法的AfterReceiveReply参数。 reply.Header是回复中所有标头的集合。