Exemplo n.º 1
0
        void SerializeResponse(
            IMessage responseMsg,
            ref ITransportHeaders responseHeaders,
            ref Stream responseStream)
        {
            XmlRpcResponseSerializer serializer = new XmlRpcResponseSerializer();

            responseStream  = new MemoryStream();
            responseHeaders = new TransportHeaders();

            ReturnMessage retMsg = (ReturnMessage)responseMsg;

            if (retMsg.Exception == null)
            {
                XmlRpcResponse xmlRpcResp = new XmlRpcResponse(retMsg.ReturnValue);
                serializer.SerializeResponse(responseStream, xmlRpcResp);
            }
            else if (retMsg.Exception is XmlRpcFaultException)
            {
                serializer.SerializeFaultResponse(responseStream,
                                                  (XmlRpcFaultException)retMsg.Exception);
            }
            else
            {
                serializer.SerializeFaultResponse(responseStream,
                                                  new XmlRpcFaultException(1, retMsg.Exception.Message));
            }
            responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\"";
        }
Exemplo n.º 2
0
        public void SerializeResponseOnType()
        {
            var deserializer = new XmlRpcResponseSerializer();
            var proxy        = XmlRpcProxyGen.Create <TestMethods2>();
            var mi           = proxy.GetType().GetMethod("Bar");
            var response     = new XmlRpcResponse(IntEnum.Three, mi);
            var stm          = new MemoryStream();

            deserializer.SerializeResponse(stm, response);
            stm.Position = 0;
            var tr     = new StreamReader(stm);
            var reqstr = tr.ReadToEnd();

            reqstr.ShouldBe(
                @"<?xml version=""1.0""?>
<methodResponse>
  <params>
    <param>
      <value>
        <string>Three</string>
      </value>
    </param>
  </params>
</methodResponse>", reqstr);
        }
Exemplo n.º 3
0
        public Stream Invoke(Stream requestStream)
        {
            try
            {
                var  serializer   = new XmlRpcResponseSerializer();
                var  deserializer = new XmlRpcRequestDeserializer();
                Type type         = this.GetType();
                XmlRpcServiceAttribute serviceAttr = (XmlRpcServiceAttribute)
                                                     Attribute.GetCustomAttribute(this.GetType(),
                                                                                  typeof(XmlRpcServiceAttribute));

                if (serviceAttr != null)
                {
                    if (serviceAttr.XmlEncoding != null)
                    {
                        serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding) ?? Config.DefaultEncoding;
                    }
                    serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
                    serializer.UseIntTag         = serviceAttr.UseIntTag;
                    serializer.UseStringTag      = serviceAttr.UseStringTag;
                    serializer.UseIndentation    = serviceAttr.UseIndentation;
                    serializer.Indentation       = serviceAttr.Indentation;
                }

                XmlRpcRequest  xmlRpcReq  = deserializer.DeserializeRequest(requestStream, this.GetType());
                XmlRpcResponse xmlRpcResp = Invoke(xmlRpcReq);

                Stream responseStream = new MemoryStream();
                serializer.SerializeResponse(responseStream, xmlRpcResp);
                responseStream.Seek(0, SeekOrigin.Begin);
                return(responseStream);
            }
            catch (Exception ex)
            {
                XmlRpcFaultException fex;
                if (ex is XmlRpcException)
                {
                    fex = new XmlRpcFaultException(0, ((XmlRpcException)ex).Message);
                }
                else if (ex is XmlRpcFaultException)
                {
                    fex = (XmlRpcFaultException)ex;
                }
                else
                {
                    fex = new XmlRpcFaultException(0, ex.Message);
                }
                XmlRpcSerializer serializer     = new XmlRpcSerializer();
                Stream           responseStream = new MemoryStream();
                serializer.SerializeFaultResponse(responseStream, fex);
                responseStream.Seek(0, SeekOrigin.Begin);
                return(responseStream);
            }
        }
Exemplo n.º 4
0
 public void PaoloLiveraniProblem()
 {
     try
     {
         XmlRpcResponse resp = new XmlRpcResponse(new DataSet());
         Stream responseStream = new MemoryStream();
         var serializer = new XmlRpcResponseSerializer();
         serializer.SerializeResponse(responseStream, resp);
     }
     catch (XmlRpcInvalidReturnType ex)
     {
         string s = ex.Message;
     }
 }
Exemplo n.º 5
0
 public void PaoloLiveraniProblem()
 {
     try
     {
         XmlRpcResponse resp           = new XmlRpcResponse(new DataSet());
         Stream         responseStream = new MemoryStream();
         var            serializer     = new XmlRpcResponseSerializer();
         serializer.SerializeResponse(responseStream, resp);
     }
     catch (XmlRpcInvalidReturnType ex)
     {
         string s = ex.Message;
     }
 }
Exemplo n.º 6
0
    public Stream Invoke(Stream requestStream)
    {
      try
      {
        var serializer = new XmlRpcResponseSerializer();
        var deserializer = new XmlRpcRequestDeserializer();
        Type type = this.GetType();
        XmlRpcServiceAttribute serviceAttr = (XmlRpcServiceAttribute)
          Attribute.GetCustomAttribute(this.GetType(),
          typeof(XmlRpcServiceAttribute));

        if (serviceAttr != null)
        {
            if (serviceAttr.XmlEncoding != null)
            {
                serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding) ?? Config.DefaultEncoding;
            }
            serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
            serializer.UseIntTag = serviceAttr.UseIntTag;
            serializer.UseStringTag = serviceAttr.UseStringTag;
            serializer.UseIndentation = serviceAttr.UseIndentation;
            serializer.Indentation = serviceAttr.Indentation;
        }

        XmlRpcRequest xmlRpcReq = deserializer.DeserializeRequest(requestStream, this.GetType());
        XmlRpcResponse xmlRpcResp = Invoke(xmlRpcReq);

        Stream responseStream = new MemoryStream();
        serializer.SerializeResponse(responseStream, xmlRpcResp);
        responseStream.Seek(0, SeekOrigin.Begin);
        return responseStream;
      }
      catch (Exception ex)
      {
        XmlRpcFaultException fex;
        if (ex is XmlRpcException)
          fex = new XmlRpcFaultException(0, ((XmlRpcException)ex).Message);
        else if (ex is XmlRpcFaultException)
          fex = (XmlRpcFaultException)ex;
        else 
          fex = new XmlRpcFaultException(0, ex.Message);
        XmlRpcSerializer serializer = new XmlRpcSerializer();
        Stream responseStream = new MemoryStream();
        serializer.SerializeFaultResponse(responseStream, fex);
        responseStream.Seek(0, SeekOrigin.Begin);
        return responseStream;      
      }
    }
Exemplo n.º 7
0
        public Stream Invoke(Stream requestStream)
        {
            try
            {
                var serializer   = new XmlRpcResponseSerializer();
                var deserializer = new XmlRpcRequestDeserializer();
                var serviceAttr  = Attribute.GetCustomAttribute(GetType(), typeof(XmlRpcServiceAttribute)) as XmlRpcServiceAttribute;
                if (serviceAttr != null)
                {
                    if (serviceAttr.XmlEncoding != null)
                    {
                        serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding);
                    }
                    serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
                    serializer.UseIntTag         = serviceAttr.UseIntTag;
                    serializer.UseStringTag      = serviceAttr.UseStringTag;
                    serializer.UseIndentation    = serviceAttr.UseIndentation;
                    serializer.Indentation       = serviceAttr.Indentation;
                }

                var xmlRpcReq      = deserializer.DeserializeRequest(requestStream, GetType());
                var xmlRpcResp     = Invoke(xmlRpcReq);
                var responseStream = new MemoryStream();
                serializer.SerializeResponse(responseStream, xmlRpcResp);
                responseStream.Seek(0, SeekOrigin.Begin);
                return(responseStream);
            }
            catch (Exception ex)
            {
                XmlRpcFaultException fex;
                var xmlRpcException = ex as XmlRpcException;
                if (xmlRpcException != null)
                {
                    fex = new XmlRpcFaultException(0, xmlRpcException.Message);
                }
                else
                {
                    fex = (ex as XmlRpcFaultException)
                          ?? new XmlRpcFaultException(0, ex.Message);
                }

                var serializer     = new XmlRpcSerializer();
                var responseStream = new MemoryStream();
                serializer.SerializeFaultResponse(responseStream, fex);
                responseStream.Seek(0, SeekOrigin.Begin);
                return(responseStream);
            }
        }
Exemplo n.º 8
0
        public Stream Invoke(Stream requestStream)
        {
            try
            {
                var serializer = new XmlRpcResponseSerializer();
                var deserializer = new XmlRpcRequestDeserializer();
                var serviceAttr = Attribute.GetCustomAttribute(GetType(), typeof(XmlRpcServiceAttribute)) as XmlRpcServiceAttribute;
                if (serviceAttr != null)
                {
                    if (serviceAttr.XmlEncoding != null)
                        serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding);
                    serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
                    serializer.UseIntTag = serviceAttr.UseIntTag;
                    serializer.UseStringTag = serviceAttr.UseStringTag;
                    serializer.UseIndentation = serviceAttr.UseIndentation;
                    serializer.Indentation = serviceAttr.Indentation;
                }

                var xmlRpcReq = deserializer.DeserializeRequest(requestStream, GetType());
                var xmlRpcResp = Invoke(xmlRpcReq);
                var responseStream = new MemoryStream();
                serializer.SerializeResponse(responseStream, xmlRpcResp);
                responseStream.Seek(0, SeekOrigin.Begin);
                return responseStream;
            }
            catch (Exception ex)
            {
                XmlRpcFaultException fex;
                var xmlRpcException = ex as XmlRpcException;
                if (xmlRpcException != null)
                    fex = new XmlRpcFaultException(0, xmlRpcException.Message);
                else
                {
                    fex = (ex as XmlRpcFaultException)
                        ?? new XmlRpcFaultException(0, ex.Message);
                }

                var serializer = new XmlRpcSerializer();
                var responseStream = new MemoryStream();
                serializer.SerializeFaultResponse(responseStream, fex);
                responseStream.Seek(0, SeekOrigin.Begin);
                return responseStream;
            }
        }
Exemplo n.º 9
0
 public void SerializeResponseOnMethod()
 {
     var deserializer = new XmlRpcResponseSerializer();
     var response = new XmlRpcResponse(IntEnum.One, GetType().GetMethod("MappingReturnOnMethod"));
     var stm = new MemoryStream();
     deserializer.SerializeResponse(stm, response);
     stm.Position = 0;
     var tr = new StreamReader(stm);
     var reqstr = tr.ReadToEnd();
     reqstr.ShouldBe(
     @"<?xml version=""1.0""?>
     <methodResponse>
       <params>
     <param>
       <value>
     <string>One</string>
       </value>
     </param>
       </params>
     </methodResponse>");
 }
    public void SerializeResponseOnType()
    {
      var deserializer = new XmlRpcResponseSerializer();
      var proxy = XmlRpcProxyGen.Create<TestMethods2>();
      MethodInfo mi = proxy.GetType().GetMethod("Bar");
      var response = new XmlRpcResponse(IntEnum.Three, mi);
      var stm = new MemoryStream();
      deserializer.SerializeResponse(stm, response);
      stm.Position = 0;
      TextReader tr = new StreamReader(stm);
      string reqstr = tr.ReadToEnd();
      Assert.AreEqual(
@"<?xml version=""1.0""?>
<methodResponse>
  <params>
    <param>
      <value>
        <string>Three</string>
      </value>
    </param>
  </params>
</methodResponse>", reqstr);
    }
Exemplo n.º 11
0
        public void SerializeResponseOnMethod()
        {
            var deserializer = new XmlRpcResponseSerializer();
            var response     = new XmlRpcResponse(IntEnum.One, GetType().GetMethod("MappingReturnOnMethod"));
            var stm          = new MemoryStream();

            deserializer.SerializeResponse(stm, response);
            stm.Position = 0;
            var tr     = new StreamReader(stm);
            var reqstr = tr.ReadToEnd();

            reqstr.ShouldBe(
                @"<?xml version=""1.0""?>
<methodResponse>
  <params>
    <param>
      <value>
        <string>One</string>
      </value>
    </param>
  </params>
</methodResponse>");
        }
    void SerializeResponse(
      IMessage responseMsg,
      ref ITransportHeaders responseHeaders, 
      ref Stream responseStream)
    {
      XmlRpcResponseSerializer serializer = new XmlRpcResponseSerializer();
      responseStream = new MemoryStream();
      responseHeaders = new TransportHeaders();

      ReturnMessage retMsg = (ReturnMessage)responseMsg;
      if (retMsg.Exception == null)
      {
        XmlRpcResponse xmlRpcResp = new XmlRpcResponse(retMsg.ReturnValue);
        serializer.SerializeResponse(responseStream, xmlRpcResp);
      }
      else if (retMsg.Exception is XmlRpcFaultException)
      {
        serializer.SerializeFaultResponse(responseStream, 
          (XmlRpcFaultException)retMsg.Exception);
      }
      else
      {
        serializer.SerializeFaultResponse(responseStream,
          new XmlRpcFaultException(1, retMsg.Exception.Message));
      }
      responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\"";
    }