wood burning stoves*
The moose likes Web Services and the fly likes SOAP Fault for SOAP Action property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "SOAP Fault for SOAP Action property" Watch "SOAP Fault for SOAP Action property" New topic
Author

SOAP Fault for SOAP Action property

Harish Vembu
Ranch Hand

Joined: Jul 19, 2004
Posts: 33


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 .


Harish
SCJP ,SCDJWS
Ravi C Kota
Ranch Hand

Joined: Jan 29, 2008
Posts: 61
Hi Harish,

When I looked into the wsdl provided, I see that soapAction is set to "http://www.webserviceX.NET/GetQuote". But I believe, since you have not set this in your program, it must be failing. Adding SOAPAction Header, should be able to guide you.


Thanks & Regards, Ravi C.Kota
SCJP 5.0, OCDJWS 5.0
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1176
The WSDL has -



Seems not follow the BP -

A DESCRIPTION SHOULD NOT have more than one wsdl:port with the same value for the location attribute of the soapbind:address element.


Not sure if it relates to your issue...

Regards,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

Hi Dan,

I'm not contradicting the specs here, but just curious, if a service is designed to handle different bindings, but its physical location is only one, why should NOT location be same here. Should not the location attribute, actually refer to the physical address where the service is deployed? I may be wrong here, but curious.


Regards
KumarRaja

Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1176
It would be interesting to see your full HTTP request and comparing it with the example provided.

Yours -



Example -



Regards,
Dan
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1176
Kumar Raja wrote:

I'm not contradicting the specs here, but just curious, if a service is designed to handle different bindings, but its physical location is only one, why should NOT location be same here. Should not the location attribute, actually refer to the physical address where the service is deployed? I may be wrong here, but curious.


Maybe SOAP / Application Versioning: One wsdl:port with the same value for the location attribute of the soap:address element can shed some light on the issue.

Regards,
Dan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SOAP Fault for SOAP Action property