Dear All,
I am facing an issue of
SOAP fault when I run the sample code provided below. I am copying the
Java code and the Output for your reference below.
Java application:
_____________________________________________________________________________________________________________________________________________________________________________
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
/**
* Shows how to add a MIME header, of which SOAPAction is one.
*/
public class AddSoapAction {
private static final
String WSDL = "http://www.webservicex.net/stockquote.asmx?wsdl";
private static final String NS = "http://www.webserviceX.NET/";
public static void main(String...arg) {
new AddSoapAction().invoke();
System.out.println("\nAll done.");
}
public AddSoapAction() { }
private void invoke(){
try {
//Prepare service to call
Service service = createService();
QName portQName = new QName(NS, "StockQuoteSoap");
Dispatch<SOAPMessage> dispatch =
service.createDispatch(portQName,
SOAPMessage.class, Service.Mode.MESSAGE);
//Add SOAPAction
/* dispatch.getRequestContext().put(
Dispatch.SOAPACTION_USE_PROPERTY, "Next");
dispatch.getRequestContext().put(
Dispatch.SOAPACTION_URI_PROPERTY,
"http://www.webserviceX.NET/GetQuote");*/
//Prepare Request
SOAPMessage request = createMessage();
//send request and get response
SOAPMessage response = dispatch.invoke(request);
//Write response to console
System.out.println("\nGot Response:\n");
response.writeTo(System.out);
System.out.println("\n");
} catch (Exception ex) {
ex.printStackTrace();
}
}
private SOAPMessage createMessage() throws SOAPException {
//Create a SOAPMessage
MessageFactory messageFactory =
MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
try {
SOAPEnvelope env = message.getSOAPPart().getEnvelope();
SOAPBody body = env.getBody();
//Create a SOAPBodyElement
QName bodyName = new QName("http://www.webserviceX.NET/",
"GetQuote");
SOAPBodyElement bodyEl = body.addBodyElement(bodyName);
//Add our data
QName name = new QName("symbol");
SOAPElement symbol = bodyEl.addChildElement(name);
symbol.addTextNode("JAVA");
System.out.println("\nCreated Request:\n");
message.writeTo(System.out);
System.out.println("\n");
} catch (Exception e) {
System.out.println(e.getMessage());
}
return message;
}
private Service createService() throws MalformedURLException {
URL wsdl = new URL(WSDL);
//Create the Service name
String svcName = "StockQuote";
QName svcQName = new QName(NS, svcName);
//Get a delegate wrapper
Service service = Service.create(wsdl, svcQName);
System.out.println("Created Service: " + service.getServiceName());
return service;
}
}
_________________________________________________________________________________________________________________________________
Output :
Created Service: {http://www.webserviceX.NET/}StockQuote
Created Request:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><GetQuote xmlns="http://www.webserviceX.NET/"><symbol>IBM</symbol></GetQuote></SOAP-ENV:Body></SOAP-ENV:Envelope>
Got Response:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><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.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& abortProcessing)</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
All done.
___________________________________________________________________________________________________________________________________________________________
Can anyone assist me in letting me know as to why its giving SOAP fault ?. Is so how to construct and send a proper SOAP message. The web service hosted on remote server somehow doesn't like the value for SOAP action property : SOAPACTION_USE_PROPERTY, "1"
Any help would be much appreciated

.