Convert string to a C class #

Asked

Viewed 63 times

0

I am doing an integration with an API in SOAP, in one of the methods need to pass as parameter a value of an API class, the problem is that I receive this parameter in the format String and need to convert it to the proprietary class Token of the API. I tried to use the code below without success, where I get the following error:

Error CS0266 Cannot implicitly convert type 'object' to 'WebService.Token'. An explicit conversion exists (are you missing a cast?)

Note: I tried to add the implicit element, but could not.

My code:

 NFeClient client = new();
    
    var result = client.SendOperation(arq);

//error converting string to Token class
    Token token = Convert.ChangeType(result.ReturnCode, typeof(string)); 
    var result = client.SendFile(token);
    
    Class that will receive the parameter:
    public partial class NFeClient : ServiceModel.ClientBase<WebService.INFe>, WebServiceTransben.INFe
    {
        public WebService.RetornoOfint SendFile(Token token)
        {
            return base.Channel.SendFile(token);
        } 
    }
    
    private string ReturnCodeField;
    public string ReturnCode
    {
            get
        {
            return this.ReturnCodeField;
        }
            set
        {
            this.ReturnCodeField = value;
        }
    }

1 answer

2


After this code here, just initialize and pass the token that will

  public Token ReturnCode{get;set;}

Browser other questions tagged

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