using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel.Description; using System.ServiceModel.Dispatcher; using System.ServiceModel; using System.Windows.Forms; using System.ServiceModel.Channels; public static class CustomHeaderNames { public const String CustomHeaderName = "UsernameToken"; public const String UserName = "user"; public const String PassName = "pass"; public const String CustomHeaderNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; } public class CustomHeader : MessageHeader { private String _user, _pass; public String user { get { return (this._user); } } public String pass { get { return (this._pass); } } public CustomHeader(String user, String pass) { this._user = user; this._pass = pass; } public override string Name { get { return (CustomHeaderNames.CustomHeaderName); } } public override string Namespace { get { return (CustomHeaderNames.CustomHeaderNamespace); } } protected override void OnWriteHeaderContents(System.Xml.XmlDictionaryWriter writer, MessageVersion messageVersion) { // Write the content of the header directly using the XmlDictionaryWriter writer.WriteElementString(CustomHeaderNames.UserName, this.user); writer.WriteElementString(CustomHeaderNames.PassName, this.pass); } public static CustomHeader ReadHeader(System.Xml.XmlDictionaryReader reader) { // Read the header content (key) using the XmlDictionaryReader if (reader.ReadToDescendant(CustomHeaderNames.UserName, CustomHeaderNames.CustomHeaderNamespace)) { String user = reader.ReadElementString("user"); String pass = reader.ReadElementString("pass"); return (new CustomHeader(user, pass)); } else { return null; } } } public class MyMessageInspector : IClientMessageInspector { //static string response; public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState) { try { //Console.WriteLine(reply.ToString()); //MessageBox.Show(reply.ToString()); string ret = reply.ToString().Substring(reply.ToString().IndexOf("") + 1); ret = ret.Substring(0, ret.ToString().IndexOf(" data) { string json = Newtonsoft.Json.JsonConvert.SerializeObject(data); try { SOAPWorker.call.createDocument( new BS_SOAP_API.APIService.createDocumentRequest((object)json) ); return int.Parse(response.Replace("\"", "")); } catch (Exception e) { e.GetType(); return -1; } } public static int SearchContacts(Dictionary data) { string json = Newtonsoft.Json.JsonConvert.SerializeObject(data); SOAPWorker.call.searchContacts( new BS_SOAP_API.APIService.searchContactsRequest((object)json) ); try { //Console.WriteLine(response); return Newtonsoft.Json.JsonConvert.DeserializeObject(response)[0]; //return int.Parse(response); } catch (Exception e) { e.GetType(); return -1; } } public static Dictionary getUserAccount(string name) { Dictionary data = new Dictionary(); data["usrnam"] = name; string json = Newtonsoft.Json.JsonConvert.SerializeObject(data); SOAPWorker.call.getUserAccount( new BS_SOAP_API.APIService.getUserAccountRequest((object)json) ); try { return Newtonsoft.Json.JsonConvert.DeserializeObject>(response); } catch (Exception e) { e.GetType(); return null; } } public static Dictionary GetContactData(int id) { //string json = Newtonsoft.Json.JsonConvert.SerializeObject(data); SOAPWorker.call.getContact( new BS_SOAP_API.APIService.getContactRequest((object)id) ); try { //Console.WriteLine(response); return Newtonsoft.Json.JsonConvert.DeserializeObject>(response); // return int.Parse(response); } catch (Exception e) { e.GetType(); return null; } } public static int GetTypeOfDocumentData(string name) { Dictionary data = new Dictionary(); data["dctptp"] = name; string json = Newtonsoft.Json.JsonConvert.SerializeObject(data); try { SOAPWorker.call.getDocumentTypeData( new BS_SOAP_API.APIService.getDocumentTypeDataRequest((object)json) ); Dictionary resp = Newtonsoft.Json.JsonConvert.DeserializeObject>(response.Trim(new char[]{'[',']'})); return int.Parse((string)resp["dctpid"]); } catch (Exception e) { e.GetType(); return -1; } } } }