locked
Web service using web reference : decimal attribute value can't be set RRS feed

  • Question

  • User1792445881 posted

    Hi i'm trying to consume a soap web service :

    so i used web reference to do it :

    I have an attribute of type decimal and of use optional:

    Here's my WSDL:

    <xsd:attribute name="taxes" use="optional">
            <xsd:simpleType>
              <xsd:restriction base="xsd:decimal">
                <xsd:totalDigits value="9" />
                <xsd:fractionDigits value="2" />
                <xsd:maxInclusive value="9999999.99" />
              </xsd:restriction>
            </xsd:simpleType>
          </xsd:attribute>

    I want to set this attribute, the problem that its value is not modified, But when I changev" use "attribute to required the value is changed.

    Here' the code :

    public partial class CreationFacturationWS : System.Web.UI.Page
    {
    public string clientID;
    protected void Page_Load(object sender, EventArgs e)
    {
        string clientID = GetClientID("http://*******/axis2/services/****/");
    
    
    }
    
    public static string GetClientID(string url)
    {
        //Srd.reponseDisponibiliteReponse[] response = null;
        Srd.wsboif service = new Srd.wsboif();
    
        //l'url du service
        service.Url = url;
    
        //temps d'attente maximal de la réponse (ms)
        service.Timeout = 10000;
    
        demandeCommande depotDeCommande = new demandeCommande();
    
        //Avec Frais de port inclus
        //2 produits dans la commande
        depotDeCommande.montantPaiementGlobal = 32.48M;// decimal and required ---> works
        depotDeCommande.taxes = 7.5M;//decimal and optional -->don't work
    
      ....

    I test the "  use=optional " option to a string value it works fine here's the used code :

    <xsd:attribute name="codeTVA" use="optional">
       <xsd:simpleType>
             <xsd:restriction base="xsd:string">
             <xsd:maxLength value="3" />
           </xsd:restriction>
        </xsd:simpleType>
    </xsd:attribute>

    I think it's a bug , What do you think?

    Any help will be appreciated

    Thank you in advance



    Monday, July 22, 2013 4:37 AM

Answers

  • User-742633084 posted

    Hi amiramanai,

    So the problem you encounter is that the optional field (attribute) works for string type but not for decimal type, correct?

    I think this is likely due to the fact that demical is a primitive type which is mapping to value type (instead of reference type like string, object) in .NET Framework. Therefore, although the XML schema defines it as "optional", but .NET Framework side generate the field as a normal primitive value type one. For testing, you can try open the source code file of the generate webservice client proxy and check the class field of that optional attribute. If it is a simple "decimal" type field, you can try changing it to a .NET nullable type like "decimal?" in C# to see whether if it helps.

    here are some web reference discussing on similar topics

    #ASMX 2.0 - Nullable Types
    http://adrianba.net/archive/2005/03/02/5aa86125c57a40c3b3a22662304beb16.aspx

    #The Web services empire strikes back - Support for Nullable<T> and SqlTypes http://weblogs.asp.net/cweyer/archive/2004/10/30/250018.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 29, 2013 4:07 AM