Exemplo n.º 1
0
        private RK7QueryResult SendRequest(string requestHost, RK7QueryRK7CMD requestObject, Type requestResultType)
        {
            // curl -k -u user:pass -i -X POST -H "Content-Type: text/xml" -d @comand.xml "http://xxx.xxx.xxx.xxx.:2237/rk7api/v0/xmlinterface.xml"

            var query = new RK7Query {
                RK7CMD = requestObject
            };

            var httpRequest = new HttpRequestMessage(HttpMethod.Post, requestHost)
            {
                Content = new StringContent(GetXMLRequest(query),
                                            Encoding.GetEncoding(1251),
                                            "text/xml")
            };

            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            var responce = Client.SendAsync(httpRequest);

            responce.Wait();
            var responceContent = responce.Result.Content;

            var serializer = new XmlSerializer(requestResultType);
            var streamTask = responceContent.ReadAsStreamAsync();

            streamTask.Wait();
            return(serializer.Deserialize(streamTask.Result) as RK7QueryResult);
        }
Exemplo n.º 2
0
 private string SerializeQuery(RK7Query RK7Query)
 {
     using (var textWriter = new StringWriter())
     {
         new XmlSerializer(RK7Query.GetType()).Serialize(textWriter, RK7Query);
         _logger.LogTrace("Serialize Query: {textWriter}", textWriter.ToString());
         return(textWriter.ToString());
     }
 }
Exemplo n.º 3
0
 private string GetXMLRequest(RK7Query request)
 {
     using (var textWriter = new StringWriter())
     {
         var serializer = new XmlSerializer(request.GetType());
         serializer.Serialize(textWriter, request);
         return(textWriter.ToString());
     }
 }