Foros del Web » Programación para mayores de 30 ;) » .NET »

[SOLUCIONADO] Mantener la sesion

Estas en el tema de Mantener la sesion en el foro de .NET en Foros del Web. Hola ¿Sabeis como mantener la sesion en un cliente .Net de C# paa un webservice de Java? En Java , esta setMaintainSession(true) de AXIS , ...
  #1 (permalink)  
Antiguo 23/09/2015, 11:30
 
Fecha de Ingreso: noviembre-2014
Mensajes: 22
Antigüedad: 9 años, 5 meses
Puntos: 0
Mantener la sesion

Hola

¿Sabeis como mantener la sesion en un cliente .Net de C# paa un webservice de Java?

En Java , esta setMaintainSession(true) de AXIS , pero no encuentro el equivalente en C#

Saludos
  #2 (permalink)  
Antiguo 23/09/2015, 11:36
(Desactivado)
 
Fecha de Ingreso: enero-2015
Mensajes: 393
Antigüedad: 9 años, 3 meses
Puntos: 52
Respuesta: Mantener la sesion

¿Como estas consumiendo el servicio? Algo de código por favor.
  #3 (permalink)  
Antiguo 23/09/2015, 11:40
 
Fecha de Ingreso: noviembre-2014
Mensajes: 22
Antigüedad: 9 años, 5 meses
Puntos: 0
Respuesta: Mantener la sesion

Hola

Genero el cliente , usando el generador de C#

static void Main(string[] args)
{
CalculadoraClient cal = new CalculadoraClient();

while (true)
{
Console.WriteLine(cal.getSes());
}
}

Donde getSes me devuelve el identificador de sesion (operacion realizada en java)

Codigo del cliente generado

//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18444
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace WebService.ServiceReference1.calc {


[System.CodeDom.Compiler.GeneratedCodeAttribute("Sy stem.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Names pace="http://miCalc", ConfigurationName="ServiceReference1.calc.Calculad ora")]
public interface Calculadora {

[System.ServiceModel.OperationContractAttribute(Act ion="", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(S tyle=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded )]
[return: System.ServiceModel.MessageParameterAttribute(Name ="getURLReturn")]
string getURL();

[System.ServiceModel.OperationContractAttribute(Act ion="", ReplyAction="*")]
[return: System.ServiceModel.MessageParameterAttribute(Name ="getURLReturn")]
System.Threading.Tasks.Task<string> getURLAsync();

[System.ServiceModel.OperationContractAttribute(Act ion="", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(S tyle=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded )]
[return: System.ServiceModel.MessageParameterAttribute(Name ="sumaReturn")]
int suma(int x, int y);

[System.ServiceModel.OperationContractAttribute(Act ion="", ReplyAction="*")]
[return: System.ServiceModel.MessageParameterAttribute(Name ="sumaReturn")]
System.Threading.Tasks.Task<int> sumaAsync(int x, int y);

[System.ServiceModel.OperationContractAttribute(Act ion="", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(S tyle=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded )]
[return: System.ServiceModel.MessageParameterAttribute(Name ="getVersionWebReturn")]
int getVersionWeb();

[System.ServiceModel.OperationContractAttribute(Act ion="", ReplyAction="*")]
[return: System.ServiceModel.MessageParameterAttribute(Name ="getVersionWebReturn")]
System.Threading.Tasks.Task<int> getVersionWebAsync();

[System.ServiceModel.OperationContractAttribute(Act ion="", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(S tyle=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded )]
[return: System.ServiceModel.MessageParameterAttribute(Name ="getSesReturn")]
string getSes();

[System.ServiceModel.OperationContractAttribute(Act ion="", ReplyAction="*")]
[return: System.ServiceModel.MessageParameterAttribute(Name ="getSesReturn")]
System.Threading.Tasks.Task<string> getSesAsync();
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("Sy stem.ServiceModel", "4.0.0.0")]
public interface CalculadoraChannel : WebService.ServiceReference1.calc.Calculadora, System.ServiceModel.IClientChannel {
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Sy stem.ServiceModel", "4.0.0.0")]
public partial class CalculadoraClient : System.ServiceModel.ClientBase<WebService.ServiceR eference1.calc.Calculadora>, WebService.ServiceReference1.calc.Calculadora {

public CalculadoraClient() {

}

public CalculadoraClient(string endpointConfigurationName) :
base(endpointConfigurationName) {
}

public CalculadoraClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}

public CalculadoraClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}

public CalculadoraClient(System.ServiceModel.Channels.Bin ding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}

public string getURL() {
return base.Channel.getURL();
}

public System.Threading.Tasks.Task<string> getURLAsync() {
return base.Channel.getURLAsync();
}

public int suma(int x, int y) {
return base.Channel.suma(x, y);
}

public System.Threading.Tasks.Task<int> sumaAsync(int x, int y) {
return base.Channel.sumaAsync(x, y);
}

public int getVersionWeb() {
return base.Channel.getVersionWeb();
}

public System.Threading.Tasks.Task<int> getVersionWebAsync() {
return base.Channel.getVersionWebAsync();
}

public string getSes() {
return base.Channel.getSes();
}

public System.Threading.Tasks.Task<string> getSesAsync() {
return base.Channel.getSesAsync();
}
}
}
  #4 (permalink)  
Antiguo 23/09/2015, 12:28
(Desactivado)
 
Fecha de Ingreso: enero-2015
Mensajes: 393
Antigüedad: 9 años, 3 meses
Puntos: 52
Respuesta: Mantener la sesion

http://www.codeproject.com/Articles/...EST-Services-w

Ese post explica como hacer eso usando cookies.

Igualmente no veo por qué necesitas semejante cosa.
  #5 (permalink)  
Antiguo 23/09/2015, 12:45
 
Fecha de Ingreso: noviembre-2014
Mensajes: 22
Antigüedad: 9 años, 5 meses
Puntos: 0
Respuesta: Mantener la sesion

Hola

Eso ya lo he intentado

El problema es que el WebService esta generado en Java , y el cliente lo genera automaticamente el C# , luego no tengo acceso a a CookieContainer

Esto se usa para actualizar los webservice en caliente , sin que se entere el usuario

Saludos.
  #6 (permalink)  
Antiguo 23/09/2015, 12:49
 
Fecha de Ingreso: noviembre-2014
Mensajes: 22
Antigüedad: 9 años, 5 meses
Puntos: 0
Respuesta: Mantener la sesion

Hola

En el cliente de Java , lo he conseguido con el metodo que he expuesto , y cliente generado por Apache , no he escrito nada de codigo

El problema esta en como hacerlo en el cliente C#

Gracias
  #7 (permalink)  
Antiguo 23/09/2015, 13:20
(Desactivado)
 
Fecha de Ingreso: enero-2015
Mensajes: 393
Antigüedad: 9 años, 3 meses
Puntos: 52
Respuesta: Mantener la sesion

Sigo sin saber para qué queres eso, pero bueno:

http://www.codeproject.com/Articles/...-Service-Calls

Ahi te indica como usar un Message Inspector en WCF para modificar los headers HTTP, incluyendo cookies, etc.
  #8 (permalink)  
Antiguo 23/09/2015, 13:34
 
Fecha de Ingreso: noviembre-2014
Mensajes: 22
Antigüedad: 9 años, 5 meses
Puntos: 0
Respuesta: Mantener la sesion

Hola

Es mucho mas sencillo

http://www.wiktorzychla.com/2011/11/managing-cookies-in-wcf-client.html

El codigo queda

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;
using WebService.ServiceReference1.calc;

namespace WebService
{
class Program
{

static void Main(string[] args)


{
//CreateHttpWebRequest("http://localhost:8080/PruebaSuma/services/Calculadora?wsdl");

int c = 0;

CalculadoraClient client = new CalculadoraClient();

CookieContainer tCookieContainer = new CookieContainer();

using (new OperationContextScope(client.InnerChannel))
{
HttpRequestMessageProperty request = new HttpRequestMessageProperty();
request.Headers["Cookie"] = "cookie header value";

OperationContext.Current.OutgoingMessageProperties[
HttpRequestMessageProperty.Name] = request;

while (true)
{
Console.WriteLine(client.getSes()+" "+client.getVersionWeb()+" c="+c);
c++;
}
}

}
}
}

Y el fichero app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="CalculadoraSoapBinding" allowCookies="true"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/PruebaSuma/services/Calculadora"
binding="basicHttpBinding" bindingConfiguration="CalculadoraSoapBinding"
contract="ServiceReference1.calc.Calculadora" name="Calculadora" />
</client>
</system.serviceModel>
</configuration>

Es importante remarcar que allowCookies="true"

Gracias por la ayuda

Etiquetas: net
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:35.