Okay this is how you do it .. partly ..

The result I have now looks like this
<Version Identification="SKARABEEPRO" Major="0" Minor="0" Build="0"
Revision="0" />  

The only thing missing is
xmlns="http://XXX"; 

and that is the last part that I can't get in ..
I tried this but that gives compile errors
version.setAttributeNS(Constants.NS_URI_SOAP_ENV, "xmlns",
"http://xxx";);

Can someone please give some help ? :)
One more line of code would be enough (I hope)

Thanx
Tom


Code so far ...


// create a non-validating, namespace aware doc-builder
DocumentBuilder db =
org.apache.soap.util.xml.XMLParserUtils.getXMLDocBuilder();
                Document doc = db.newDocument();

                // create header, declare namespace, add element to
entries
                Header header = new Header();
        
                Element version = doc.createElementNS("", "Version");
                version.setAttributeNS(Constants.NS_URI_SOAP_ENV,
"Identification", "SKARABEEPRO");
                version.setAttributeNS(Constants.NS_URI_SOAP_ENV,
"Major", "0");
                version.setAttributeNS(Constants.NS_URI_SOAP_ENV,
"Minor", "0");
                version.setAttributeNS(Constants.NS_URI_SOAP_ENV,
"Revision", "0");
                version.setAttributeNS(Constants.NS_URI_SOAP_ENV,
"Build", "0");
                Vector entries = new Vector();
                entries.addElement(version);

                // set the entries and header
                header.setHeaderEntries(entries);

-----Original Message-----
From: Tom Leuntjens 
Sent: Thursday, June 13, 2002 10:11 AM
To: [EMAIL PROTECTED]
Subject: RE: Correct way to add Apache SOAP Header ?

Hmm,
I've been looking but to no success ..
I'm stuck and not much info is at hand 

Could someone give some sample code on how to do this ?
It's not clear how I need to proceed ...

If I have a node .. how to get this into the header ?

I need to get this in  the header ..
<Version Identification="SKARABEEPRO" Major="0" Minor="0" Build="0"
Revision="0" xmlns="XXX" />  

-----Original Message-----
From: Greg Symons [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, June 11, 2002 10:03 PM
To: [EMAIL PROTECTED]
Subject: RE: Correct way to add Apache SOAP Header ?

The problem you're having here is in the way you are using the Header
object. What you're doing will actually create this for the header:

<soap:Header Version Identification="SKARABEEPRO" Major="0" Minor="0"
Build="0" Revision="0"/>

What you should be doing is creating a org.w3c.dom.Node object and
adding it to the header entries using setHeaderEntries on your Header
object. Also, by passing in the empty string as your namespace prefix,
I'm guessing weird things are gonna happen with the namespace
declarations... unless that was deleted so you could post:)




 __________________________________
|                                  \
|  Greg Symons                     /
|  Systems Analyst                 \
|  Research Federal Credit Union   /
|  (586) 264-8710 x1234            \
|__________________________________/ 
-----Original Message-----
From: Tom Leuntjens [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, June 11, 2002 8:57 AM
To: [EMAIL PROTECTED]
Subject: RE: Correct way to add Apache SOAP Header ?


The problem is that I need to compose this little piece header ... and
add it to the call (I think) ..
 
  <soap:Header>    <Version Identification="SKARABEEPRO" Major="0"
Minor="0" Build="0" Revision="0" xmlns="XXX" />  </soap:Header>  
I' don't really see how I need to do this with APACHE SOAP API
 
Code so far .....
 
import java.io.*;
import java.util.*;
import java.net.*;
import org.w3c.dom.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
import org.apache.soap.transport.http.SOAPHTTPConnection;
 
public class testClient {
 
            public static void main(String[] args) throws Exception {
 
                        URL url = new URL
("http://xxx/dataswitch23.asmx";);
                        String SOAPAction = "http://xxx/core23/Ping";;
                        SOAPMappingRegistry smr = new
SOAPMappingRegistry();
                        StringDeserializer sd = new StringDeserializer
();
                        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new
QName ("", "Result"), null, null, sd);
 
 
                        // create the transport and set parameters
                        SOAPHTTPConnection st = new
SOAPHTTPConnection();
                        st.setUserName("xxxx");
                        st.setPassword("xxx");
 
                        // create the header
                        Header myHeader = new Header();
                        myHeader.declareNamespace("", " XXX ");
                        myHeader.setAttribute(new QName("",
"Identification"), "SKARABEEPRO");
                        myHeader.setAttribute(new QName("", "Major"),
"0");
                        myHeader.setAttribute(new QName("", "Minor"),
"0");
                        myHeader.setAttribute(new QName("", "Revision"),
"0");
                        myHeader.setAttribute(new QName("", "Build"),
"0");
 
/*
 
System.out.println("\n------------------------------------------------\n
");
                        System.out.println(myHeader.toString());
*/
 
 
                        // build the call.
                        Call call = new Call ();
                        call.setSOAPTransport(st);
                        call.setSOAPMappingRegistry (smr);
                        call.setTargetObjectURI
("http://xxx/service/dataswitch23.asmx";);
                        call.setMethodName("Ping");
                        call.setEncodingStyleURI
("Constants.NS_URI_SOAP_ENC");
                        call.setHeader(myHeader);
 
 
/*
 
System.out.println("\n------------------------------------------------\n
");
                        System.out.println(call.toString());
 
System.out.println("\n------------------------------------------------\n
");
*/
 
                        Response resp = null;
                        try {
                          resp = call.invoke (url, SOAPAction);
                        }
                        catch (SOAPException e) {
                                    System.err.println("Caught
SOAPException (" + e.getFaultCode () + "): " + e.getMessage ());
                                    return;
                        }
 
                        // check response
                        if (resp != null && !resp.generatedFault()) {
                           Parameter ret = resp.getReturnValue();
                          Object value = ret.getValue();
 
                          System.out.println ("Answer--> " + value);
                        }
                        else {
                                    Fault fault = resp.getFault ();
                                    System.err.println ("Generated
fault: ");
                                    System.out.println (" Fault Code = "
+ fault.getFaultCode());
                                    System.out.println (" Fault String =
" + fault.getFaultString());
                        }
            }
}
 
 
the error I keep getting ...
Server did not find required Version SOAP header in the message
 
 
 
-----Original Message-----
From: Wimmer, Matthias [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, June 11, 2002 2:42 PM
To: '[EMAIL PROTECTED]'
Subject: RE: Correct way to add Apache SOAP Header ?
 
Tom:
 
What is your problem? Doesn't it work? So below you will find an example
I found:
 
        Element emailElem = doc.createElementNS(
"http://any.namespace.com";,  "EMail");
        emailElem.appendChild( ... );
        SOAPEnvelope reqEnv = new SOAPEnvelope();
        reqEnv.addHeader( new SOAPHeader(emailElem ));
        reqEnv.addBodyElement( ... );
        
        // Invoke the web service
        Call call = new Call( url );
        SOAPEnvelope respEnv = call.invoke(reqEnv);
I hope it works like this.
 
best regards
Matthias Wimmer
-----Original Message-----
From: Tom Leuntjens [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 11, 2002 7:01 AM
To: [EMAIL PROTECTED]
Subject: Correct way to add Apache SOAP Header ?
Hi, 
So far im creating the call and i get this :
System.Web.Services.Protocols.SoapHeaderException: Server did not find
required Version SOAP header in the message. 
So I have been trying to add the header like this but to no avail .. 
 
 
// create the headerHeader myHeader = new
Header();myHeader.declareNamespace("Version", "");
myHeader.setAttribute(new QName("", "Identification"), "SKARABEEPRO");
myHeader.setAttribute(new QName("", "Major"),
"0");myHeader.setAttribute(new QName("", "Minor"),
"0");myHeader.setAttribute(new QName("", "Revision"),
"0");myHeader.setAttribute(new QName("", "Build"), "0"); //add the
header to the call ...call.setHeader(myHeader);
Can somebody can give me some more info on how to do this ? What is the
correct way to add the header (details below)? Don't seem to find any
info about it ... 
Any help is appreciated ..
Thanx
Regards,
Tom

The service requires this call: 
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>  <soap:Header>
<Version Identification="SKARABEEPRO" Major="0" Minor="0" Build="0"
Revision="0" xmlns="leftthisouttopost" />  </soap:Header>  <soap:Body>
<Ping xmlns="leftthisouttopost" />  </soap:Body></soap:Envelope>
The toString() of the call (for my code at the time that doesn't work)
gives this : 
[Header=[Attributes={ Build="0" Revision="0" xmlns:Version=""
Identification="SKARABEEPRO" Minor="0" Major="0"}] [HeaderEntries={}]]
[methodName=Ping] [targetObjectURI=leftthisouttopostonforum]
[encodingStyleURI=Constants.NS_URI_SOAP_ENC] [SOAPContext=[Parts={}]]
[Params={}] 

Reply via email to