|
package myPackage;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class MyService implements com.bea.jws.WebService
{
/** @common:control */
private myPackage.MyServiceCtl myServiceControl;
static final long serialVersionUID = 1L;
/**
* @common:operation
*/
public void myMethod()
{
Document doc = null; //allocate a document
try
{
//create the document
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
doc = factory.newDocumentBuilder().newDocument();
}
catch (ParserConfigurationException pce)
{
//should do something here.
}
// create the <SOAP-ENV:Header> element
Element header = doc.createElementNS(
"http://schemas.xmlsoap.org/soap/envelope/",
"SOAP-ENV:Header");
// create the <my:Content> element
Element headerContent = doc.createElementNS(
"http://my.org/uri/",
"my:Content");
header.appendChild(headerContent);
// insert the text in the content node
headerContent.appendChild(doc.createTextNode("Content Text"));
Attr nsAttr = doc.createAttributeNS(
"http://www.w3.org/2000/xmlns/",
"xmlns:my");
nsAttr.setValue("http://my.org/uri/");
headerContent.setAttributeNodeNS(nsAttr);
myServiceControl.setOutputHeaders(new Element[] {header});
myServiceControl.serviceMethod("argument");
}
}
|