I'm consuming a Web service developed in C #, from an Android application. When sending simple types per parameter such as string, int, or long, I can get the information usually just by putting the same type in the Web service method declaration parameter. But I do not know how to get a complex object created in java within the web service method in C #. The submitted object has the same name in both applications, but they are not exactly the same because of property names.
-I'm using Ksoap2 on android, and the class is being serialized and sent to the web service without any errors. -maybe I could get the object as XML, but what kind would I put on the face?
Call web service
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo object = new PropertyInfo();
object.setName("obj");
object.setValue(ordemServicoBO);
object.setType(ordemServicoBO.getClass());
request.addProperty(object);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.ENC;
envelope.setOutputSoapObject(request);
envelope.addMapping(NAMESPACE, "ordemServicoBO",new OrdemServicoBO().getClass());
envelope.implicitTypes = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
androidHttpTransport.call(SOAP_ACTION, envelope);//Aqui a chamada é feita normalmente sem erro, e entra no método do web service
SoapObject responseNoXML = (SoapObject)envelope.bodyIn;
Java class
public class OrdemServicoBO implements KvmSerializable {
private long idOrdemServico;
private long IdOrdemServicoCategoria;
private long idOrdemServicoLocal;
private long idHotel;
private long idUsuarioExecutante;
private long idUsuarioSolicitante;
private long idArea;
private String dataAbertura;
private String descricao;
private String status;
private AreaBO areaBO;
private UsuarioBO usuarioSolicitante;
private UsuarioBO usuarioExecutante;
private OrdemServicoCategoriaBO ordemServicoCategoriaBO;
public void setOrdemServicoCategoriaBO(OrdemServicoCategoriaBO ordemServicoCategoriaBO) {
this.ordemServicoCategoriaBO = ordemServicoCategoriaBO;
}
public OrdemServicoCategoriaBO getOrdemServicoCategoriaBO() {
return ordemServicoCategoriaBO;
}
public void setUsuarioExecutante(UsuarioBO usuarioExecutante) {
this.usuarioExecutante = usuarioExecutante;
}
public void setUsuarioSolicitante(UsuarioBO usuarioSolicitante) {
this.usuarioSolicitante = usuarioSolicitante;
}
public UsuarioBO getUsuarioExecutante() {
return usuarioExecutante;
}
public UsuarioBO getUsuarioSolicitante() {
return usuarioSolicitante;
}
public void setDataAbertura(String dataAbertura) {
this.dataAbertura = dataAbertura;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public void setIdArea(long idArea) {
this.idArea = idArea;
}
public void setIdHotel(long idHotel) {
this.idHotel = idHotel;
}
public void setIdOrdemServico(long idOrdemServico) {
this.idOrdemServico = idOrdemServico;
}
public void setIdOrdemServicoCategoria(long idOrdemServicoCategoria) {
IdOrdemServicoCategoria = idOrdemServicoCategoria;
}
public void setIdOrdemServicoLocal(long idOrdemServicoLocal) {
this.idOrdemServicoLocal = idOrdemServicoLocal;
}
public void setIdUsuarioExecutante(long idUsuarioExecutante) {
this.idUsuarioExecutante = idUsuarioExecutante;
}
public void setIdUsuarioSolicitante(long idUsuarioSolicitante) {
this.idUsuarioSolicitante = idUsuarioSolicitante;
}
public void setStatus(String status) {
this.status = status;
}
public String getDataAbertura() {
return dataAbertura;
}
public long getIdArea() {
return idArea;
}
public long getIdHotel() {
return idHotel;
}
public long getIdOrdemServico() {
return idOrdemServico;
}
public long getIdOrdemServicoCategoria() {
return IdOrdemServicoCategoria;
}
public long getIdOrdemServicoLocal() {
return idOrdemServicoLocal;
}
public long getIdUsuarioExecutante() {
return idUsuarioExecutante;
}
public long getIdUsuarioSolicitante() {
return idUsuarioSolicitante;
}
public String getDescricao() {
return descricao;
}
public String getStatus() {
return status;
}
public void setAreaBO(AreaBO areaBO) {
this.areaBO = areaBO;
}
public AreaBO getAreaBO() {
return areaBO;
}
@Override
public Object getProperty(int arg0)
{
switch(arg0)
{
case 0:
return getDataAbertura();
case 1:
return getDescricao();
case 2:
return getStatus();
case 3:
return getIdOrdemServicoCategoria();
case 4:
return getIdOrdemServico();
case 5:
return getIdOrdemServicoLocal();
case 6:
return getIdArea();
case 7:
return getIdHotel();
case 8:
return getIdUsuarioExecutante();
case 9:
return getIdUsuarioSolicitante();
}
return null;
}
@Override
public void setProperty(int arg0, Object arg1)
{
switch(arg0)
{
case 0:
setDataAbertura(arg1.toString());
break;
case 1:
setDescricao(arg1.toString());
break;
case 2:
setStatus(arg1.toString());
break;
case 3:
setIdOrdemServicoCategoria(Long.parseLong(arg1.toString()));
break;
case 4:
setIdOrdemServico(Long.parseLong(arg1.toString()));
break;
case 5:
setIdOrdemServicoLocal(Long.parseLong(arg1.toString()));
break;
case 6:
setIdArea(Long.parseLong(arg1.toString()));
break;
case 7:
setIdHotel(Long.parseLong(arg1.toString()));
break;
case 8:
setIdUsuarioExecutante(Long.parseLong(arg1.toString()));
break;
case 9:
setIdUsuarioSolicitante(Long.parseLong(arg1.toString()));
break;
}
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2)
{
switch(arg0)
{
case 0:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "CategoryId";
break;
case 1:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Description";
break;
case 2:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Name";
break;
case 3:
arg2.type = PropertyInfo.INTEGER_CLASS;
arg2.name = "CategoryId";
break;
case 4:
arg2.type = PropertyInfo.INTEGER_CLASS;
arg2.name = "CategoryId";
break;
case 5:
arg2.type = PropertyInfo.INTEGER_CLASS;
arg2.name = "CategoryId";
break;
case 6:
arg2.type = PropertyInfo.INTEGER_CLASS;
arg2.name = "CategoryId";
break;
case 7:
arg2.type = PropertyInfo.INTEGER_CLASS;
arg2.name = "CategoryId";
break;
case 8:
arg2.type = PropertyInfo.INTEGER_CLASS;
arg2.name = "CategoryId";
break;
case 9:
arg2.type = PropertyInfo.INTEGER_CLASS;
arg2.name = "CategoryId";
break;
default:break;
}
}
@Override
public int getPropertyCount()
{
return 10;
}
}
Web service method C #
[WebMethod]
public OrdemServicoBO Exportar(OrdemServicoBO ordemServicoBO)//quando é executado o androidHttpTransport.call() é chamado esse método, mas o retorno, que é o mesno recebido por parâmetro, esta vazio.
{
return ordemServicoBO; //Atualmente retorna vazio
}
Class in C #
public class OrdemServicoBOAPP
{
private long _idOrdemServico;
public long IdOrdemServico
{
get { return _idOrdemServico; }
set { _idOrdemServico = value; }
}
private long _IdOrdemServicoCategoria;
public long IdOrdemServicoCategoria
{
get { return _IdOrdemServicoCategoria; }
set { _IdOrdemServicoCategoria = value; }
}
private long _idOrdemServicoLocal;
public long IdOrdemServicoLocal
{
get { return _idOrdemServicoLocal; }
set { _idOrdemServicoLocal = value; }
}
private long _idHotel;
public long IdHotel
{
get { return _idHotel; }
set { _idHotel = value; }
}
private long _idUsuarioExecutante;
public long IdUsuarioExecutante
{
get { return _idUsuarioExecutante; }
set { _idUsuarioExecutante = value; }
}
private long _idUsuarioSolicitante;
public long IdUsuarioSolicitante
{
get { return _idUsuarioSolicitante; }
set { _idUsuarioSolicitante = value; }
}
private long _idArea;
public long IdArea
{
get { return _idArea; }
set { _idArea = value; }
}
private String _dataAbertura;
public String DataAbertura
{
get { return _dataAbertura; }
set { _dataAbertura = value; }
}
private string _descricao;
public string Descricao
{
get { return _descricao; }
set { _descricao = value; }
}
private string _status;
public string Status
{
get { return _status; }
set { _status = value; }
}
private AreaBOAPP _areaBO;
public AreaBOAPP AreaBO
{
get { return _areaBO; }
set { _areaBO = value; }
}
}