SoapAction Http Header for SAAJ
843834Jul 29 2002 — edited Jul 29 2002I am trying to communicate with a server that requires the SoapAction HttpHeader. This has been deprecated in SOAP 1.2, but we still have to send it.
So using javax.xml.soap.* classes, how do I add a HTTP header to the message. Adding a soap header is easy, but that is not what they want.
WSDL can be found: http://terraservice.net/terraservice.asmx?WSDL
**************** Description **********************
POST /TerraService.asmx HTTP/1.1
Host: terraservice.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://terraservice.net/terraserver/ConvertLonLatPtToUtmPt"
<?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:Body>
<ConvertLonLatPtToUtmPt xmlns="http://terraservice.net/terraserver/">
<point>
<Lon>double</Lon>
<Lat>double</Lat>
</point>
</ConvertLonLatPtToUtmPt>
</soap:Body>
</soap:Envelope>
********************* My Request **********************
<?xml version="1.0" encoding="UTF-8"?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://terraservice.net/terraserver/ConvertLonLatPtToUtmPt">
<soap-env:Header/>
<soap-env:Body>
<m:ConvertLonLatPtToUtmPt>
<m:Lon>45.0</m:Lon>
<m:Lat>-111.0</m:Lat>
</m:ConvertLonLatPtToUtmPt>
</soap-env:Body>
</soap-env:Envelope>
************************ My Code ************************
public void execute() throws SOAPException, IOException
{
SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = connectionFactory.createConnection();
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
//SOAPHeader header = envelope.getHeader();
String namespacePrefix = "m";
String methodName = "ConvertLonLatPtToUtmPt";
String namespaceUri = "http://terraservice.net/terraserver/ConvertLonLatPtToUtmPt";
envelope.addNamespaceDeclaration(namespacePrefix,namespaceUri);
namespacePrefix, namespaceUri));
"http://bowstreet.com/2002/03/models/xmethods/gcd");
SOAPBody body = envelope.getBody();
SOAPBodyElement method1 = body.addBodyElement(envelope.createName(methodName, namespacePrefix, namespaceUri));
SOAPElement child1 = method1.addChildElement("Lon", namespacePrefix);
child1.addTextNode("45.0");
SOAPElement child2 = method1.addChildElement("Lat", namespacePrefix);
child2.addTextNode("-111.0");
message.saveChanges();
URLEndpoint endpoint = new URLEndpoint("http://terraservice.net/terraservice.asmx");
message.writeTo(System.out);
SOAPMessage reply = connection.call(message, endpoint);
reply.writeTo(System.out);
connection.close();
}
************************** Response ***********************8
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: .
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
Thanx,
Aaron Roller