0
votes

How I can receive a class as parameter within asmx class? and as I can validate that the class contains data?

My class:

  public class ws_loginViewModel
    {
        public int user { get; set; }

        public string pass { get; set; }
    }

My method within asmx class

public int Login(ws_loginViewModel user)

when cosuming this method without send parameter, i have the next error

soap:Client System.Web.Services.Protocols.SoapException: El servidor no puede leer la solicitud. ---> System.InvalidOperationException: Error en el documento XML (7, 41). ---> System.FormatException: La cadena de entrada no tiene el formato correcto. en System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) en System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) ...

I consume with SoapUi software and it generate this xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:vac="">
   <soapenv:Header/>
   <soapenv:Body>
      <vac:Login>
         <!--Optional:-->
         <vac:user>
            <vac:user>?</vac:user>
            <!--Optional:-->
            <vac:pass>?</vac:pass>
         </vac:user>
      </vac:Login>
   </soapenv:Body>
</soapenv:Envelope>
1
What is the XML which produces this error? If "the input string is not in the correct format" then that usually means you're trying to convert a string to a non-string value which it doesn't represent. In this case perhaps a non-integer value for the user property. - David
Hi @David I consume this with SoapUi Software. I just edit the question - Diego Flores

1 Answers

2
votes

Based on the XML you provided in a comment:

<soapenv:Envelope xmlns:soapenv="schemas.xmlsoap.org/soap/envelope/"; xmlns:vac="vacaciones">
<soapenv:Header/>
  <soapenv:Body>
    <vac:Logeo>
      <!--Optional:-->
      <vac:usuario>
        <vac:usuario>?</vac:usuario>
        <!--Optional:-->
        <vac:clave>?</vac:clave>
      </vac:usuario>
    </vac:Logeo>
  </soapenv:Body>
</soapenv:Envelope>

Pay specific attention to this part:

<vac:usuario>?</vac:usuario>

And to this part of your class:

public int user { get; set; }

A "?" character can't be converted to an integer. Ideally there is some schema validation which a consuming client should use to ensure that the request is valid. But, regardless, the request is invalid. You need to supply an integer value for the integer property.