Java Reference
In-Depth Information
<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.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest
(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type,
HttpContext context, HttpRequest request, HttpResponse response,
Boolean&amp; abortProcessing)</faultstring><detail
/></soap:Fault></soap:Body></soap:Envelope>
Apparently, the server is not too happy with the message you've sent and complains that it
needs a value for the SOAPAction header. Add one to your request message by changing your
createSOAPRequest method to look like this:
private static SOAPMessage createSOAPRequest(String stockSymbol)
throws Exception {
// Construct a new SOAP request message
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
// Construct the SOAP "body" with the method arguments
// Add a SOAP action header to the request
// Action: http://www.webserviceX.NET/GetQuote
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", SERVICE_HOST + SERVICE_METHOD);
// Save our changes
soapMessage.saveChanges();
// Print out the request message:
System.out.println("Sending SOAP request:");
soapMessage.writeTo(System.out);
System.out.println("\r\n");
return soapMessage;
}
This piece of code will add the following HTTP header to your request:
SOAPAction: " http://www.webserviceX.NET/GetQuote"
If you followed along with the “Exploring SOAP Services” Try It Out, you already saw this
SOAPAction header in the example provided by WebserviceX.NET . In most cases, the SOAPAction
header combines the hostname with the SOAP operation ( GetQuote ). Later on in this chapter, you'll
see how you can use WSDL to provide this information.
If you execute this code once more, you now get a different reply from the server.
Sending SOAP request:
<SOAP-ENV:Envelope xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/">
Search WWH ::




Custom Search