Send ENUM parameter to C# via Javascript

Asked

Viewed 173 times

0

I am developing a project in which I have to consume a Web Service in . NET that requires an object with some parameters of type Enum.

The call is made by Javascript as below:

function ConsultarPeriodo(){
	  var metodo = 'ConsultarPeriodo';
	  var url = baseURL.dadoscliente;
	  
	  var param = {		  
			canal : 'LOJA',			
			empresa : 'Teste',            
			loja : '0',
			usuario : 'Teste'            
	  };
	  
	  return $soap.post(url, metodo, { req: param });  
  }

The attributes "channel" and "company" are of type Enum in the Web Service. NET that I am consuming, so I need to send the parameters so that the web service recognizes the Enum attributes.

Enum code:

 public enum EmpresaType
{

    /// <remarks/>
    Loja1,

    /// <remarks/>
    Loja2,

    /// <remarks/>
    Loja3,
}


public enum CanalType
{

    /// <remarks/>
    LOJA,

    /// <remarks/>
    ECOMMERCE,
}

What my code would look like?

Thank you!

  • 1

    Only put the numeric value of Enum.

  • And in case the enums were not created with numerical values?

  • Write the name of the value.

  • You have access to the Enum code to post here?

  • All right, I made it available!

  • Detail, the class that references enums is inside a web Referral of an external service that I added in my application, thinking that the problem is this. I did a test creating the same external Ws class in my application, but creating the attributes as XML attribute, and functioned. Since WS is external and I can’t change, I guess I’ll have to create an internal class to do the "from x to".

  • Did you run a test by passing the numerical values of Enum? Ex: Function Query Eriododad(){ var method = 'Query Eriododad'; var url = baseURL.dadoscliente; var param = ' channel :0, company : 1, store : '899', user : 'Test#&Xa; }; Return $Soap.post(url, method, { req: param }); }

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.