首页 > 代码库 > wcf xml消息客户端cookie
wcf xml消息客户端cookie
public override bool Login(string userName, string password) { using (HttpClient client = new HttpClient(URI)) { StringBuilder sb = new StringBuilder(); sb.Append("Login"); Uri uri = new Uri(URI + sb.ToString()); Login lg = new Login(); lg.userName = userName; lg.password = password; HttpContent content = HttpContentExtensions.CreateXmlSerializable<Login>(lg, null); StringBuilder conntentStr = new StringBuilder(); //string s = content.ReadAsString(); using (HttpRequestMessage request = new HttpRequestMessage("POST", uri, content)) { request.Headers.Accept.AddString(accepts); using (HttpResponseMessage response = client.Send(request)) { Microsoft.Http.Headers.Cookie cook=null; if(response.Headers.SetCookie!=null && response.Headers.SetCookie.Count>0) { cook= response.Headers.SetCookie[0]; CookieMe.SaveCookie(cook["YourAuth"]); } Stream result = response.Content.ReadAsStream(); XmlSerializer ser = new XmlSerializer(typeof(LoginResponse));//将对象序列化到xml文档 LoginResponse lr = (LoginResponse)ser.Deserialize(result); return lr.LoginResult; } } } }
使用wcf starter kit,注意协定操作方法名和参数的序列化是一起的,因为服务端使用了
BodyStyle = WebMessageBodyStyle.Wrapped
注意序列化时的对象名必须与协定中的方法参数名大小写一致,否则会出现错误
登陆后客户端需要保存cookie,远程调用其他操作都要先向HttpRequestMessage对象添加cookie
request.Headers.Cookie.Add(cookie);
wcf xml消息客户端cookie
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。