Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/02/2012, 18:58
SolisUNMSM
 
Fecha de Ingreso: enero-2011
Ubicación: lima-peru
Mensajes: 80
Antigüedad: 13 años, 3 meses
Puntos: 4
Exclamación wcf rest envio de tildes y enies

Hola foro

aquí un problema que no le encontrado solución
ps tengo un servicio wcf rest en un iis7

esta es mi simple interfaz

Código C++:
Ver original
  1. [ServiceContract]
  2.     public interface ISAERegistro
  3.     {
  4.         #region "test"
  5.  
  6.         [OperationContract]
  7.         [WebInvoke(
  8.             Method = "PUT",
  9.             RequestFormat = WebMessageFormat.Json,
  10.             ResponseFormat = WebMessageFormat.Json,
  11.             UriTemplate = "/testSendGetObject",
  12.             BodyStyle = WebMessageBodyStyle.WrappedRequest)]
  13.         TestEntity testSendObject(TestEntity sendGetObject);
  14.  
  15.         [OperationContract]
  16.         [WebInvoke(
  17.             Method = "PUT",
  18.             RequestFormat = WebMessageFormat.Json,
  19.             ResponseFormat = WebMessageFormat.Json,
  20.             UriTemplate = "/testAloneSendObject",
  21.             BodyStyle = WebMessageBodyStyle.Wrapped)]
  22.         void testAloneSendObject(TestEntity sendObject);
  23.  
  24.         [OperationContract]
  25.         [WebGet(
  26.             UriTemplate = "/testAloneGetObject",
  27.             ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json,
  28.             BodyStyle = WebMessageBodyStyle.WrappedRequest
  29.             )]        
  30.         TestEntity testAloneGetObject();
  31.  
  32.  
  33.         [OperationContract]
  34.         [WebInvoke(
  35.             Method = "PUT",
  36.             RequestFormat = WebMessageFormat.Json,
  37.             ResponseFormat = WebMessageFormat.Json,
  38.             UriTemplate = "/testSendGetString/{sendGetString}",
  39.             BodyStyle = WebMessageBodyStyle.WrappedRequest)]
  40.         string testSendGetString(string sendGetString);
  41.  
  42.         [OperationContract]
  43.         [WebInvoke(
  44.             Method = "PUT",
  45.             RequestFormat = WebMessageFormat.Json,
  46.             ResponseFormat = WebMessageFormat.Json,
  47.             UriTemplate = "/testAloneSendString/{sendString}",
  48.             BodyStyle = WebMessageBodyStyle.Wrapped)]
  49.         void testSendString(string sendString);
  50.  
  51.         [OperationContract]
  52.         [WebGet(
  53.             UriTemplate = "/testAloneGetString",
  54.             ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json
  55.             )]
  56.         string testGetString();
  57.  
  58.         #endregion
  59.  
  60.      
  61.     }


la entidad
Código vb:
Ver original
  1. namespace LuzDelSur.Tecnico.SAE.Registro.WCFEntity
  2. {
  3.     [DataContract( Name="TestEntity " , Namespace="") ]
  4.     public class TestEntity
  5.     {
  6.        
  7.           [DataMember( Name="nombre", Order=1)]
  8.         public string nombre  { get; set; }        
  9.          [DataMember (Name="algo" , Order=2) ]
  10.         public string algo  { get; set; }
  11.        
  12.      
  13.    }
  14.  
  15.  
  16. }

y la implementacion del servicio

Código C++:
Ver original
  1. public class SAERegistro : ISAERegistro
  2.     {
  3.        
  4.        
  5.         #region "test"
  6.  
  7.         public TestEntity testSendObject(TestEntity sendGetObject) {
  8.             return sendGetObject;
  9.         }
  10.  
  11.         public void testAloneSendObject(TestEntity sendObject) {
  12.             //:D
  13.         }
  14.  
  15.         public TestEntity testAloneGetObject() {
  16.             TestEntity tes = new TestEntity();
  17.             tes.algo = "abcdefghijklmnñopqrstuvwxyz";
  18.             tes.nombre = "´qweeraáéíóúñÑ!#$$%$&%&/(&?=))=(()/(&/%(/&°¬°/*'";
  19.             return tes;
  20.         }
  21.  
  22.         public string testSendGetString(string sendGetString) {
  23.             return sendGetString;
  24.         }
  25.         public void testSendString(string sendString) {
  26.             //:D
  27.         }
  28.         public string testGetString(){
  29.             return "´qweeraáéíóúñÑ!#$$%$&%&/(&?=))=(()/(&/%(/&°¬°/*'";
  30.         }
  31.  
  32.  
  33.         #endregion
  34.  
  35.      
  36.     }

y mi cliente en android


Código Javascript:
Ver original
  1. httpClient = HttpClientFactory.getDefaultHttpClient();
  2.    
  3.                
  4.         T salida = null;
  5.         String aux = urlServidor + "/" + servicio.toString();
  6.         aux = aux.trim();
  7.  
  8.         /**
  9.          * este esplit se hace para formatear la peticion a una URI valida este
  10.          * error se daba por ejeplo se daba una paametro con acentos o espacios
  11.          */
  12. //      String[] parts = aux.split(":");
  13. //     
  14. //      if(port!=null){
  15. //          parts[1]+=":"+port+"/"+servicio.toString();
  16. //      }
  17. //     
  18. //          URI uri = new URI(parts[0], parts[1], null);
  19.  
  20.         aux = (URI.create(aux)).toString();
  21.  
  22.         StringEntity input = new StringEntity("{" + entityRequest.toString()
  23.                 + "}");
  24.  
  25.        
  26.         input.setContentType("application/json;charset=ISO-8859-1");// text/plain;charset=UTF-8
  27.  
  28.    
  29.        
  30.         testingMonitor.writeLog("test", "URI parseada:" + aux);
  31.         testingMonitor.writeLog("test", "entity a ser enviada :: {"
  32.                 + entityRequest.toString() + "}");
  33.  
  34.         switch (metodo) {
  35.        
  36.         case RestClientConstants.Metodo.PUT:
  37.             testingMonitor.writeLog("test", ">PUT");
  38.             HttpPut putRequest = new HttpPut(aux);
  39.  
  40.         //  putRequest.setHeader("Accept", "text/json");
  41.             putRequest.setHeader("Content-type", "text/json; charset=ISO-8859-1");
  42.            
  43.             if (!input.equals("{}")) {
  44.                 //input.setContentType("text/json");
  45.                 putRequest.setEntity(input);
  46.                 testingMonitor.writeLog("test", "aniadio entity");
  47.             } else {
  48.                 testingMonitor.writeLog("test", "no aniadio entity");
  49.             }
  50.  
  51.             response = ejecutarMetodoSincrono(putRequest);
  52.             // br = new BufferedReader( new
  53.             // InputStreamReader((response.getEntity().getContent())));
  54.  
  55.             // limpiar el entytiRequest al final de la petición
  56.  
  57.             break;
  58.  
  59.         }
  60.    
  61.         br = new BufferedReader( new InputStreamReader((response.getEntity().getContent())));
  62.        
  63.         entityRequest.delete(0, entityRequest.length());
  64.         servicio = new StringBuilder();
  65.  
  66.         testingMonitor.writeLog("test", "estatus code:"
  67.                 + response.getStatusLine().getStatusCode());
  68.  
  69.         if (response.getStatusLine().getStatusCode() != 200) {
  70.  
  71.                         String json=br.readLine();
  72.        
  73.            
  74.                     throw new RuntimeException("Failed : HTTP error code : "
  75.                         + response.getStatusLine().getStatusCode());
  76.  
  77.         }
  78.  
  79.         if (c != null) {
  80.             String json=br.readLine();
  81. //          String json = br;
  82.             json = json.trim();
  83.             testingMonitor.writeLog("test", "json repuesta:" + json);
  84.             if (json.length() > 0) {
  85.                 salida = (T) gs.fromJson(json, c);
  86.             }
  87.             testingMonitor.writeLog("test",
  88.                     "salida clase parseada :" + salida.toString());
  89.         }
  90.  
  91.        
  92.         return salida;
  93.     }

basicamente , tiene mas codigo pero eso es lo que ejecuta para consumir el servicio , todo ok mientras no halla carcater como la enie o tildes ,

cuando envio y recibo string con simbolos raros no problemas
el problema es cuando el estring esta dentro de una clase como atributo , el esrvidor me reopnde con code estatus 400

.aniado l codigo que parsea el objeton

Código C++:
Ver original
  1. @Override
  2.     public void addObjetoRequest(String var, Object obj) {
  3.         entityRequest.append("\"");
  4.         entityRequest.append(var);
  5.         entityRequest.append("\":");
  6.         entityRequest.append(gs.toJson(obj));
  7.     }

alguien le ha pasado? ...qeu encoder reibe el servicio wcf , talves tenga que configurar su web config . nose ,.espero alguna luz sobre esto , gracias.