Ejemplo n.º 1
0
        public void DeserializeResponseStructWithNil()
        {
            string         xml          = @"<?xml version=""1.0"" ?> 
<methodResponse>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>lowerBound</name>
            <value><nil/></value>
          </member>
          <member>
            <name>upperBound</name>
            <value><nil/></value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodResponse>";
            StringReader   sr           = new StringReader(xml);
            var            deserializer = new XmlRpcResponseDeserializer();
            XmlRpcResponse response     = deserializer.DeserializeResponse(sr, typeof(ServerBounds));

            Assert.IsInstanceOf <ServerBounds>(response.retVal);
            ServerBounds bounds = response.retVal as ServerBounds;

            Assert.IsNull(bounds.lowerBound);
            Assert.IsNull(bounds.upperBound);
        }
Ejemplo n.º 2
0
        public object Invoke(MethodInfo methodInfo, params object[] parameters)
        {
            var request = XmlRpcClientProtocol.MakeXmlRpcRequest(methodInfo, parameters);

            using var memoryStream = new MemoryStream();
            var serializer = new XmlRpcRequestSerializer(Configuration);

            serializer.SerializeRequest(memoryStream, request);

            memoryStream.Seek(0, SeekOrigin.Begin);
            using var requestMessage = new HttpRequestMessage()
                  {
                      Method  = HttpMethod.Post,
                      Content = new StreamContent(memoryStream)
                  };

            using var response = _client.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult();
            response.EnsureSuccessStatusCode();

            using var responseStream = response.Content.ReadAsStreamAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            var deserializer   = new XmlRpcResponseDeserializer(Configuration);
            var responseAnswer = deserializer.DeserializeResponse(responseStream, request.MethodInfo.ReturnType);

            return(responseAnswer.ReturnValue);
        }
Ejemplo n.º 3
0
        public void DeserializeResponseNilMethod()
        {
            string         xml          = @"<?xml version=""1.0"" ?> 
<methodResponse>
  <params>
    <param>
      <value><nil /></value>
    </param>
  </params>
</methodCall>";
            StringReader   sr           = new StringReader(xml);
            var            deserializer = new XmlRpcResponseDeserializer();
            XmlRpcResponse response     = deserializer.DeserializeResponse(sr, this.GetType());

            Assert.IsNull(response.retVal, "return value is null");
        }
Ejemplo n.º 4
0
        public TResponse Invoke <TDefinitionResponse, TResponse>(Func <TService, TDefinitionResponse> method)
        {
            TResponse response = default(TResponse);

            XmlRpcResponseEventHandler responseHandler = (sender, args) =>
            {
                var            deserializer = new XmlRpcResponseDeserializer();
                XmlRpcResponse res          = deserializer.DeserializeResponse(args.ResponseStream, typeof(TResponse));
                response = (TResponse)res.retVal;
            };

            using (ProxyManager <TService> manager = CreateProxyManager(responseHandler))
            {
                method(manager);
            }

            return(response);
        }
Ejemplo n.º 5
0
        public void Deserialize()
        {
            string xml =
                @"<?xml version=""1.0"" encoding=""iso-8859-1""?>
<methodResponse>
  <params>
    <param>
      <value>
        <i4>2</i4>
      </value>
    </param>
  </params>
</methodResponse>";
            StringReader   sr1          = new StringReader(xml);
            var            deserializer = new XmlRpcResponseDeserializer();
            XmlRpcResponse response     = deserializer.DeserializeResponse(sr1,
                                                                           typeof(IntEnum));
            IntEnum ret = (IntEnum)response.retVal;

            Assert.AreEqual(IntEnum.Two, ret);
        }