Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

SOAP Fault for SOAP Action property

 
Ranch Hand
Posts: 33
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 .

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic