is there a way to control tag names in generated soap message

Discussion in 'ASP .Net Web Services' started by mike, May 12, 2005.

  1. mike

    mike Guest

    When I define a webservice:


    SOURCE:

    [WebMethod]
    public string Crunch(string bite)
    {
    return "{"+ruff.ToLower()+"}";
    }

    SOAP REQUEST:

    <soap:Envelope ..... >
    <soap:Body>
    <Crunch>
    <bite>string</bite>
    </Crunch>
    </soap:Body>
    </soap:Envelope>

    SOAP RESPONSE:

    <soap:Envelope ...... >
    <soap:Body>
    <CrunchResponse>
    <CrunchResult>string</CrunchResult>
    </CrunchResponse>
    </soap:Body>
    </soap:Envelope>

    Is there a simple way to control names for generated tags? For example
    changing "CrunchResult" to "Crunch" for return values and changing
    "bite" to "Arg" (instead of changing argument name in the source code).
     
    mike, May 12, 2005
    #1
    1. Advertising

  2. mike

    Brock Allen Guest

    You can control those via custom attributes applied to the method, parameters
    and return value. Here's the XmlElementAttribute docs to get you started:

    http://msdn.microsoft.com/library/d...erializationXmlElementAttributeClassTopic.asp

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > When I define a webservice:
    >
    > SOURCE:
    >
    > [WebMethod]
    > public string Crunch(string bite)
    > {
    > return "{"+ruff.ToLower()+"}";
    > }
    > SOAP REQUEST:
    >
    > <soap:Envelope ..... >
    > <soap:Body>
    > <Crunch>
    > <bite>string</bite>
    > </Crunch>
    > </soap:Body>
    > </soap:Envelope>
    > SOAP RESPONSE:
    >
    > <soap:Envelope ...... >
    > <soap:Body>
    > <CrunchResponse>
    > <CrunchResult>string</CrunchResult>
    > </CrunchResponse>
    > </soap:Body>
    > </soap:Envelope>
    > Is there a simple way to control names for generated tags? For example
    > changing "CrunchResult" to "Crunch" for return values and changing
    > "bite" to "Arg" (instead of changing argument name in the source
    > code).
    >
     
    Brock Allen, May 12, 2005
    #2
    1. Advertising

  3. mike

    mike Guest

    Hello Allen,

    Yes, I did look into that and I missed AttributeTargets.ReturnValue.
    Now that is in place. How do I use it? :)

    [WebMethod]
    public [XmlElement("MYCUSTOM")] string Crunch(string bite)
    {
    return "{"+ruff.ToLower()+"}";
    }

    That does not compile. How do I attach an attribute to a return value?

    Next, will it change <CrunchResult> to <MYCUSTOM> if this is somehow
    above is fixed and attribute is applied correctly.
     
    mike, May 12, 2005
    #3
  4. mike

    mike Guest

    Hello Allen,

    I asked the question back too quickly without looking around. :)

    [WebMethod]
    [return: XmlElement("MYCUSTOM")]
    public string Crunch(string bite)
    {
    return "{"+ruff.ToLower()+"}";
    }

    works ok now with the seap response as

    <soap:Envelope ...... >
    <soap:Body>
    <CrunchResponse>
    <MYCUSTOM>string</MYCUSTOM>
    </CrunchResponse>
    </soap:Body>
    </soap:Envelope>

    thanks
     
    mike, May 13, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Corey
    Replies:
    0
    Views:
    307
    Jim Corey
    Jun 30, 2004
  2. rabbits77
    Replies:
    0
    Views:
    875
    rabbits77
    Feb 26, 2004
  3. John
    Replies:
    8
    Views:
    923
    iksrazal
    Mar 28, 2005
  4. shruds
    Replies:
    1
    Views:
    827
    John C. Bollinger
    Jan 27, 2006
  5. Peter van der veen

    How to add SOAP header to a SOAP message?

    Peter van der veen, Nov 8, 2006, in forum: ASP .Net Web Services
    Replies:
    6
    Views:
    591
    J. Dudgeon
    Nov 14, 2006
Loading...

Share This Page