I'm trying to call a SOAP webservice using SAAJ for this WSDL. I submitted the request for this WSDL here http://www.webservicex.net/ws/WSDetails.aspx?WSID=64and it generated the following SOAP requests..
<?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>
<GetGeoIP xmlns="http://www.webservicex.net/">
<IPAddress>string</IPAddress>
</GetGeoIP>
</soap:Body>
</soap:Envelope>
Using SAAJ I generated the same SOAP requests and submitted it but get this error - Server did not recognize the value of HTTP Header SOAPAction: .
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Header/>
<SOAP-ENV:Body>
<GetGeoIP xmlns="http://www.webservicex.net/">
<IPAddress>SUNW</IPAddress>
</GetGeoIP>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Java Code:
package newpackage;
import javax.xml.namespace.QName;
import javax.xml.soap.*;
public class SOAPClientSAAJ {
public static void main(String args[]) throws Exception {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String url = "http://www.webservicex.net/geoipservice.asmx";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
// print SOAP Response
System.out.print("Response SOAP Message:");
soapResponse.writeTo(System.out);
soapConnection.close();
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://www.w3.org/2001/XMLSchema";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("xsd", serverURI);
SOAPBody body = soapMessage.getSOAPBody();
QName bodyName = new QName("http://www.webservicex.net/", "GetGeoIP" );
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
QName name = new QName("IPAddress");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("SUNW");
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message:");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
}
Add
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", "http://www.webservicex.net/" + "GetGeoIP");
If you are using Marshelling and Unmarsheling, Just implement WebseviceMessageCallback interface like:
public class SOAPConnector extends WebServiceGatewaySupport
{
public Object callWebService( String url, Object request )
{
return getWebServiceTemplate().marshalSendAndReceive( url, request,
webServiceMessage -> {
(( SoapMessage )webServiceMessage).setSoapAction(
"https://www.w3schools.com/xml/CelsiusToFahrenheit" );
} );
}
}
Otherwise proceed with: https://stackoverflow.com/a/26253141/6097074
Related
I am new to SOAP. I want to create a soap request of given below xml.
xml
<?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>
<SendRequest xmlns="http://tempuri.org/">
<request xsi:type="RegisterCheckRequest" Id="7a646d45-ee2f-4b1c-8de8-780c416fbbd0" Service="42" xmlns="http://paygo24.com/v3/protocol">
<PaymentParameters xmlns="">
<Parameter Name="account" Value="08374829" />
</PaymentParameters>
</request>
<pointId>46</pointId>
<password>4QrcOUm6Wau+VuBX8g+IPg==</password>
</SendRequest>
</soap:Body>
</soap:Envelope>
I was using below sample java file, to create soap request but I am not able to do so, can anyone give me support.
Sample Java File to create soap request
import javax.xml.soap.*;
public class SOAPClientSAAJ {
public static void main(String args[]) throws Exception {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String url = "http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
// print SOAP Response
System.out.print("Response SOAP Message:");
soapResponse.writeTo(System.out);
soapConnection.close();
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://ws.cdyne.com/";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("example", serverURI);
/*
Constructed SOAP Request Message:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="http://ws.cdyne.com/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<example:VerifyEmail>
<example:email>mutantninja#gmail.com</example:email>
<example:LicenseKey>123</example:LicenseKey>
</example:VerifyEmail>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
*/
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("VerifyEmail", "example");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("email", "example");
soapBodyElem1.addTextNode("mutantninja#gmail.com");
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("LicenseKey", "example");
soapBodyElem2.addTextNode("123");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "VerifyEmail");
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message:");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
}
This is how you build soap request
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.removeNamespaceDeclaration(envelope.getPrefix());
envelope.addNamespaceDeclaration("soap","http://schemas.xmlsoap.org/soap/envelope/");
envelope.setPrefix("soap");
envelope.addNamespaceDeclaration("xsi","http://www.w3.org/2001/XMLSchema-instance");
envelope.addNamespaceDeclaration("xsd","http://www.w3.org/2001/XMLSchema");
SOAPHeader header=soapMessage.getSOAPHeader();
header.setPrefix("soap");
SOAPBody soapBody = envelope.getBody();
soapBody.setPrefix("soap");
SOAPElement root=soapBody.addChildElement(new QName("http://tempuri.org/","SendRequest"));
SOAPElement request=root.addChildElement(new QName("http://paygo24.com/v3/protocol","request"));
request.setAttribute("xsi:type", "RegisterCheckRequest");
request.setAttribute("Id","7a646d45-ee2f-4b1c-8de8-780c416fbbd0");
request.setAttribute("Service","42");
SOAPElement paymentParameters =request.addChildElement(new QName(" ","PaymentParameters"));
SOAPElement parameter=paymentParameters.addChildElement("Parameter");
parameter.setAttribute("Name","account");
parameter.setAttribute("Value", "08374829");
root.addChildElement("pointId").setValue("46");
root.addChildElement("password").setValue("4QrcOUm6Wau+VuBX8g+IPg==");
soapMessage.saveChanges();
soapMessage.writeTo(System.out);
return soapMessage;
}
You can generate XML from objects using annotations to tie class members to XML elements/attributes. A popular way is using JAX-B. See this tutorial: http://www.vogella.com/tutorials/JAXB/article.html
Okay, so I'm totally new to webservices and for a project I'm working on I'm trying to wrap my head around the whole SOAP thing. I think I have a vague understanding of what is going on, but I'm missing some specific information and I simply can't find anything helpful by googling.
I've read the questions others asked like this one SOAP request to WebService with java but I still can't fully figure out what is going on.
Specifically I'm trying to use the service provided here http://ec.europa.eu/taxation_customs/vies/vatRequest.html with its wsdl file here http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
I tried adapting the example given in the above question, but I just can't figure out what values to add where so it works with this specific service. All I get is a "405 Method not allowed" response. Here is my attempted adaption:
package at.kmds.soaptest;
import javax.xml.soap.*;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
public class Main {
public static void main(String args[]) {
try {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String url = "http://ec.europa.eu/taxation_customs/vies/vatRequest.html";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
// Process the SOAP Response
printSOAPResponse(soapResponse);
soapConnection.close();
} catch (Exception e) {
System.err.println("Error occurred while sending SOAP Request to Server");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://ec.europa.eu/";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("example", serverURI);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("checkVat");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("countryCode");
soapBodyElem1.addTextNode("...");
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("vatNumber");
soapBodyElem2.addTextNode("...");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "checkVat");
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message = ");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();
System.out.print("\nResponse SOAP Message = ");
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
}
}
If someone could explain to me what exactly I'm doing wrong and how to fix it or maybe even give me a working example I'd be eternally grateful...
The code has to be slightly modified to hit the service.
String url = "http://ec.europa.eu/taxation_customs/vies/services/checkVatService";
is the endpoint you have to hit (this is from the wsdl)
<wsdlsoap:address location="http://ec.europa.eu/taxation_customs/vies/services/checkVatService"/>
Note that when i hit this , i get a soap fault.Looks like the SOAPBody constructed will have to be checked again.
Request SOAP Message = <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="http://ec.europa.eu/"><SOAP-ENV:Header/><SOAP-ENV:Body><checkVat><countryCode>...</countryCode><vatNumber>...</vatNumber></checkVat></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response SOAP Message = <?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>Unexpected wrapper element checkVat found. Expected {urn:ec.europa.eu:taxud:vies:services:checkVat:types}checkVat.</faultstring></soap:Fault></soap:Body></soap:Envelope>
Edit a full program that works (looks like) , gives me invalid input because i am passing dots (...).
import javax.xml.namespace.QName;
import javax.xml.soap.*;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
public class Main {
public static void main(String args[]) {
try {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String url = "http://ec.europa.eu/taxation_customs/vies/services/checkVatService";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
// Process the SOAP Response
printSOAPResponse(soapResponse);
soapConnection.close();
} catch (Exception e) {
System.err.println("Error occurred while sending SOAP Request to Server");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://ec.europa.eu/";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("tns1", "urn:ec.europa.eu:taxud:vies:services:checkVat:types");
envelope.addNamespaceDeclaration("impl", "urn:ec.europa.eu:taxud:vies:services:checkVat");
// SOAP Body
SOAPBody soapBody = envelope.getBody();
QName bodyQName = new QName("urn:ec.europa.eu:taxud:vies:services:checkVat:types",
"checkVat", "tns1");
SOAPElement soapBodyElem = soapBody.addChildElement(bodyQName);
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement(new QName("urn:ec.europa.eu:taxud:vies:services:checkVat:types",
"countryCode", "tns1"));
soapBodyElem1.addTextNode("...");
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement(new QName("urn:ec.europa.eu:taxud:vies:services:checkVat:types",
"vatNumber", "tns1"));
soapBodyElem2.addTextNode("...");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "checkVat");
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message = ");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();
System.out.print("\nResponse SOAP Message = ");
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
}
}
Gives back
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>INVALID_INPUT</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
I was reading a lot of tutorials and similar questions on stackoverflow, but I still have a problem connecting to my SOAP service.
I am trying to call a SOAP web service using Java. I found a nice answer here: https://stackoverflow.com/a/15942217/2145530
The example works perfectly as is but when I change it to another wsdl file it no longer works:
public static void main(String args[]) throws Exception {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String url = "http://192.168.200.165/soap/server.php";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
// print SOAP Response
System.out.print("Response SOAP Message:");
soapResponse.writeTo(System.out);
soapConnection.close();
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "urn:BoardSOAP";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("soap", serverURI);
System.out.println(envelope.getNamespaceURI());
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "getBoardStatus");
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message:");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
As you can see I changed those lines:
String url = "http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx";
String serverURI = "http://ws.cdyne.com/";
headers.addHeader("SOAPAction", serverURI + "ReturnCodes");
String url = "http://192.168.200.165/soap/server.php";
String serverURI = "urn:BoardSOAP";
headers.addHeader("SOAPAction", serverURI + "getBoardStatus");
Here is my wsdl file:
Full output:
http://schemas.xmlsoap.org/soap/envelope/
Request SOAP Message:<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="urn:BoardSOAP"><SOAP-ENV:Header/><SOAP-ENV:Body/></SOAP-ENV:Envelope>
Response SOAP Message:<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><SOAP-ENV:Fault><faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode><faultactor xsi:type="xsd:string"></faultactor><faultstring xsi:type="xsd:string">Operation '' is not defined in the WSDL for this service</faultstring><detail xsi:type="xsd:string"></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
WSDL file isn't corrupted, I can communicate with it via SoupUI with no problem.
In the answer you cite, the soapAction for ReturnCodes is http://ws.cdyne.com/ReturnCodes, which is constructed by the line headers.addHeader("SOAPAction", serverURI + "ReturnCodes");
However, in your WSDL, since you are using not a URL but a URN for your namespace identifier, the soapAction for getBoardStatus is urn:server#getBoardStatus. If you use the same concatenation scheme, you will be missing the # and you will be using urn:BoardSoap instead of urn:server.
Try using `headers.Header("SOAPAction", "urn:server#getBoardStatus").
This way also worked for me:
saajSoapMessage.setSoapAction("urn:server#getBoardStatus");
I'm very new to soap and i found an example of how to do a request here: Working Soap client example
Using a chrome plugin i've managed to find a soap query string that works which is:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetMyProjectCharges xmlns="http://company.IWWeb.Data.Service.ProjectCharges">
<Employee>26270</Employee>
<FiscalYear>2015</FiscalYear>
<ApiKey>APIKEY</ApiKey>
<AppName>APPNAME</AppName>
</GetMyProjectCharges>
</Body>
</Envelope>
So trying the code posted from the stack post I wrote:
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://schemas.xmlsoap.org/soap/envelope/";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
/*
Constructed SOAP Request Message:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="http://ws.cdyne.com/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<example:VerifyEmail>
<example:email>mutantninja#gmail.com</example:email>
<example:LicenseKey>123</example:LicenseKey>
</example:VerifyEmail>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
*/
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = //soapBody.addChildElement("GetMyProjectCharges");
soapBody.addChildElement("GetMyProjectCharges", "", "http://company.IWWeb.Data.Service.ProjectCharges");
SOAPElement soapBodyEmployee = soapBodyElem.addChildElement("Employee").addTextNode("26270");
SOAPElement soapBodyFiscalYear = soapBodyElem.addChildElement("FiscalYear").addTextNode("2015");
SOAPElement soapBodyAPIKey = soapBodyElem.addChildElement("ApiKey").addTextNode("APIKEY");
SOAPElement soapBodyAppName = soapBodyElem.addChildElement("AppName").addTextNode("APPNAME");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "GetMyProjectCharges");
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message:");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
However I'm ending up with the following soap request code:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<GetMyProjectCharges xmlns="http://company.IWWeb.Data.Service.ProjectCharges">
<Employee>26270</Employee>
<FiscalYear>2015</FiscalYear>
<ApiKey>APIKEY</ApiKey>
<AppName>APPNAME</AppName>
</GetMyProjectCharges>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Which the server doesn't seem to happy about. Is there an easy way to modify what i'm doing to get a query string closer to what i want?
I am doing a project which has to access to a given web service and send data to requested parameters and get the response from service. Currently I do something which I found from a forum and it parse the data to service, but unable to get the response since its giving an error.
My sample code is below.
package webserviceexample;
import javax.xml.soap.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class aaaa {
public static void main(String args[]) {
try {
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
String url = "https://vlmt.XXX.lk:0111/VendorRecharge/services/RechargeVendorService/wsdl/";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
printSOAPResponse(soapResponse);
//soapConnection.close();
} catch (Exception e) {
System.err.println("Error occurred while sending SOAP Request to Server");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://vendor.XXX.ZZZ.com/";
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("wsdl", serverURI);
SOAPBody soapBody1 = envelope.getBody();
SOAPElement soapBodyElemX = soapBody1.addChildElement("performRecharge", "wsdl");
SOAPElement soapBodyElem1 = soapBodyElemX.addChildElement("storeId", "wsdl");
soapBodyElem1.addTextNode("LA19BNPX");
SOAPElement soapBodyElem2 = soapBodyElemX.addChildElement("password", "wsdl");
soapBodyElem2.addTextNode("thilanka#456A");
SOAPElement soapBodyElem3 = soapBodyElemX.addChildElement("mobileNo", "wsdl");
soapBodyElem3.addTextNode("751238456");
SOAPElement soapBodyElem4 = soapBodyElemX.addChildElement("Amount", "wsdl");
soapBodyElem4.addTextNode("12");
SOAPElement soapBodyElem5 = soapBodyElemX.addChildElement("vendorTransactionId", "wsdl");
soapBodyElem5.addTextNode("15");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("performRecharge", serverURI + "performRecharge");
System.out.println("");
soapMessage.saveChanges();
System.out.print("Request SOAP Message = ");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();
System.out.print("\nResponse SOAP Message = ");
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
}
}
The error I am getting is:
Request SOAP Message
<SOAP-ENV:Envelope xmlns:SOAP- ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsdl="http://vendor.virtualization.ibm.com/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<wsdl:performRecharge>
<wsdl:storeId>LA19BNPX</wsdl:storeId>
<wsdl:password>thilanka#456A</wsdl:password>
<wsdl:mobileNo>751238456</wsdl:mobileNo>
<wsdl:Amount>12</wsdl:Amount>
<wsdl:vendorTransactionId>15</wsdl:vendorTransactionId>
</wsdl:performRecharge>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Response (error)
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode>soapenv:Server.generalException</faultcode>
<faultstring>javax.xml.rpc.JAXRPCException: WSWS3122E: Error: Could not find service services/RechargeVendorService/wsdl/ referenced in URI /VendorRecharge/services/RechargeVendorService/wsdl/</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
I have to call the "performRecharge" in the web service. Please help me.
A summary of the web service is below.
Please help me overcome this. It's very important.
Thank you.
WSDL FILE
Make sure that this is the correct service URL.
Seems like you specified the wsdl location and not registered service url. Set the request url specified in the wsdl file for the service.
String url = "https://vlmt.XXX.lk:0111/VendorRecharge/services/RechargeVendorService/wsdl/";
See the location tag in your wsdl
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address
location="**http://www.examples.com/SayHello/**">
</port>
</service>