Adding fields to default header

Discussion in 'ASP .Net Web Services' started by IT Drone, Mar 4, 2005.

  1. IT Drone

    IT Drone Guest

    I'm trying to consume a Java-based web service, and the RPC style
    requires a message that looks like this:


    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
    <ns1:id soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
    soapenv:mustUnderstand="0" xsi:type="soapenc:string"
    xmlns:ns1="http://wholesaler.packet8.com/security"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">AA11</ns1:id>
    <ns2:login soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
    soapenv:mustUnderstand="0" xsi:type="soapenc:string"
    xmlns:ns2="http://wholesaler.mycompany.com/security"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Our
    Partner</ns2:login>
    <ns3:password
    soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
    soapenv:mustUnderstand="0" xsi:type="soapenc:string"
    xmlns:ns3="http://wholesaler.packet8.com/security"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">password</ns3:password>
    </soapenv:Header>
    <soapenv:Body>
    <ns4:getProductList
    soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:ns4="urn:wholesaler.mycompany.com">
    <id xsi:type="xsd:string">AA11</id>
    </ns4:getProductList>
    </soapenv:Body>
    </soapenv:Envelope>

    Now the problem is that I can't get .net to do:
    <Envelope>
    <Header>
    <login>name></login>
    </Header>
    etc.

    I only seem to be able to get it to do:
    <Envelope>
    <Header>
    <customHeader>
    <login>name></login>
    </customHeader>
    </Header>
    etc.

    I suspect that I need to use something in System.Xml.Serialization. I
    tried just adding
    [SoapAttribute( AttributeName = "login")]
    public String partnerlogin;

    to the top of my proxy class but that didn't seem to get it in the
    right place.

    How do I modify the proxy class to add these extra three fields I need
    to the generated header, without ending up with a new header inside it?



    Thanks,

    Your faithful IT Drone
     
    IT Drone, Mar 4, 2005
    #1
    1. Advertising

  2. IT Drone

    IT Drone Guest

    Okay, I'm part way there. I added to my proxy:

    SoapType(Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
    public sealed class Header : SoapHeader

    and declared the elements in it:

    [SoapElement("id")]
    public String partnerid;

    etc.

    Then in my invokation code I have:

    WholesalerGatewayService.Header myHeader = new
    WholesalerGatewayService.Header();

    myHeader.partnerlogin="My partner";
    myHeader.partnerpassword="password";
    myHeader.partnerid="AA11";
    So now I have to somehow bind this instance of my overridden header
    class back to the instance of my class. How do I do this?

    Or am I on the wrong track?
     
    IT Drone, Mar 4, 2005
    #2
    1. Advertising

  3. IT Drone

    IT Drone Guest

    Nope, it looks like this results in:

    <Envelope>
    <Header>
    <Header>
    <!-- this inner one is the one I declared -->
    <login>Foo</login>
    </Header>
    </Header>
    <Envelope>

    instead of the desired:

    <Envelope>
    <Header>
    <login>Foo</login>
    </Header>
    <Envelope>

    should I be looking at the requestcontext property in WSE as a route to
    this?

    It's a problem with consuming axis-based web services. I've seen a lot
    of other people asking this question on the net, and short of low-level
    manipulation of the stream (ugh!) I haven't seen any solutions.
     
    IT Drone, Mar 4, 2005
    #3
  4. IT Drone

    IT Drone Guest

    In case anyone else has this problem, the solution turned out to be
    creating a SOAP Extension class and adding a SOAP Extension attribute
    to the methods in the client proxy class.
     
    IT Drone, Mar 16, 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. call_me_anything
    Replies:
    4
    Views:
    499
    Pete Becker
    Sep 30, 2007
  2. Cyril.Liu
    Replies:
    0
    Views:
    476
    Cyril.Liu
    Dec 2, 2008
  3. mlt
    Replies:
    2
    Views:
    907
    Jean-Marc Bourguet
    Jan 31, 2009
  4. middletree

    how to copy from fields to other fields

    middletree, Nov 5, 2003, in forum: ASP General
    Replies:
    1
    Views:
    184
    middletree
    Nov 5, 2003
  5. Replies:
    0
    Views:
    312
Loading...

Share This Page