I have a web service running on my local apache tomcat. I can successfully talk to it via SoapUI. However, when I write a client in Java, it does not give me a response !
Here is the client code:
SOAPConnectionFactory myFct = SOAPConnectionFactory.newInstance();
SOAPConnection myCon = myFct.createConnection();
MessageFactory myMsgFct = MessageFactory.newInstance();
SOAPMessage message = myMsgFct.createMessage();
SOAPPart mySPart = message.getSOAPPart();
SOAPEnvelope myEnvp = mySPart.getEnvelope();
SOAPBody body = myEnvp.getBody();
Name bodyName = myEnvp.createName("Ping", "ws","http://ws.myeclipseide.com/");
SOAPBodyElement gltp = body.addBodyElement(bodyName);
Name myContent1 = myEnvp.createName("arg0");
SOAPElement mySymbol1 = gltp.addChildElement(myContent1);
mySymbol1.addTextNode("test");
message.saveChanges();
URLEndpoint endPt = new URLEndpoint("http://localhost:8080/PingWebService/StringPingPort?WSDL");
SOAPMessage reply = myCon.call(message, endPt);
myCon.close();
System.out.println("Response: "+reply.getContentDescription());
The call through soapUI looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.myeclipseide.com/">
<soapenv:Header/>
<soapenv:Body>
<ws:Ping>
<!--Optional:-->
<arg0>testing this</arg0>
</ws:Ping>
</soapenv:Body>
</soapenv:Envelope>
Any idea why it would not work through java???
Does not work
Exception, error message, no call,... ?
At first glance, I cannot see anything obvious but since you are using Eclipse, activate the TCP Monitor under Eclipse, issue your call by running you program from Eclipse and check what is sent on the wire.
getContentDescription() "Returns: a String describing the content of this message or null if no description has been set" and NOT the content of your message.
Try this:
ByteArrayOutputStream out = new ByteArrayOutputStream();
reply.writeTo(out);
System.out.println("Response: "+out.toString());
Related
I'm trying to send a SOAP Request to a webservice in Delphi XE5. Actually there is a WSDL available which I imported via WSDL Importer. I established a connection to this webservice with the components THTTPRIO (rio) and IdEncoderMIME1 for the HTTP Authentication Request.
The SOAP Request was build via TXMLDocument and has the following structure:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cod=NS_Codelist>
<soapenv:Header/>
<soapenv:Body>
<cod:GetLatestChangeDatesRequest>
<!--Zero or more repetitions:-->
<CodeListID>1035</CodeListID>
</cod:GetLatestChangeDatesRequest>
</soapenv:Body>
</soapenv:Envelope>
Furthermore I received the Porttype of the webservice.
codeserv:= GetCodeListPortType(true,'',rio);
These are methods from the WSDL:
codeserv.GetLatestChangeDates(const body:GetLatestChangeDatesRequestType):GetLatestChangeDatesResponseType
GetLatestChangeDatesRequestType = array of Int64;
GetLatestChangeDatesRequest = GetLatestChangeDatesRequestType;
GetLatestChangeDatesResponseType = array of CodeListLatestChangeDateType;
GetLatestChangeDatesResponse = GetLatestChangeDatesResponseType;
CodeListLatestChangeDateType
property CodeListID: Int64
property LatestChangeDate: TXSDate
I have already tried to set an array of Int64 for the parameter but then it says "element CodeListID is missing".
Unfortunately I don't find a way to send this XML SOAP Request to the webservice and to receive the response. Any ideas?
EDIT: I have tried to use the WSDL methods
var
codeserv: CodeListPortType;
arrIDs: GetLatestChangeDatesRequest;
response: GetLatestChangeDatesResponse;
begin
codeserv:= GetCodeListPortType(true,'',rio);
SetLength(arrIDs,1);
arrIDs[0]:= 1035;
response:= codeserv.GetLatestChangeDates(arrIDs);
But then I receive the following error message: 'invalid content was found starting with element 'long'. One of '{CodeListID}' is expected.'
In the SOAP Request there have to be the element CodeListID. Unfortunately it seems the method GetLatestChangeDates isn't creating the elements in the SOAP Request. The SOAP Request posted above should have been created with this method (hopefully).
I am trying to make a Xamarin forms project that gets data from an ASMX Webservice
This is the code I am using
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("SOAPAction", "http://mobile.xn--schller-golf-xjb.dk/WebServices/IndoorServices.asmx/IndoorBruttoGns");
string soapstr = string.Format(#"<?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>
< IndoorBruttoGns xmlns = ""http://mobile.xn--schller-golf-xjb.dk/WebServices"" />
</soap:Body>
</soap:Envelope>");
var response = httpClient.PostAsync("http://mobile.xn--schller-golf-xjb.dk/WebServices/IndoorServices.asmx/IndoorBruttoGns", new StringContent(soapstr, Encoding.UTF8, "application/json")).Result;
var content = response.Content.ReadAsStringAsync().Result;
return content;
The Webservice doesn't need any input but I get a 500 internal server error and I know the Webservice works because I call it from a PhoneGap project using $.ajax
I am trying to consume SOAP (external system) web service using Spring WS template as client.
I need to pass header information(security details) as header along with the soap message.
I tried adding that information into Header using java xml SOAPMessage(javax.xml.soap.SoapMessage) and trying to convert it into spring SOAPMessage(org.springframework.ws.soap.SoapMessage) later after adding header details.
but its not able to cast it, getting class cast exception as both of them are not in heirarchy.
please help me on how to pass security details on header info in spring soap message
My code is as below
public void doWithMessage(WebServiceMessage message) throws IOException,
TransformerException
SaajSoapMessage saajSoapMessage =(SaajSoapMessage)message;
SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPHeader soapHeader = soapEnvelope.getHeader();
Name headerElementName = soapEnvelope.createName("Security","wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
// Add "Security" soapHeaderElement to soapHeader
SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(headerElementName);
// This may be important for some portals!
soapHeaderElement.setActor(null);
// Add usernameToken to "Security" soapHeaderElement
SOAPElement usernameTokenSOAPElement = soapHeaderElement.addChildElement("UsernameToken");
// Add username to usernameToken
SOAPElement userNameSOAPElement = usernameTokenSOAPElement.addChildElement("Username");
userNameSOAPElement.addTextNode("myUserName");
// Add password to usernameToken
SOAPElement passwordSOAPElement = usernameTokenSOAPElement.addChildElement("Password");
passwordSOAPElement.addTextNode("myPassword");
((SoapMessage) soapMessage).setSoapAction("GetMetaDataLookUpRequestType");//exception while casting
}
And my request xml is as below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://emc.com/it/enterprise/contract/CMCContractLookupService/v1" xmlns:v11="http://emc.com/it/enterprise/data/v1">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-20">
<wsse:Username>xxxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxx</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<v1:GetContractMetaDataLookUpRequest>
<v11:GetMetaDataLookUpRequestDocument>
<v11:ContractID>123456</v11:ContractID>
<v11:BadgeID>1</v11:BadgeID>
</v11:GetMetaDataLookUpRequestDocument>
</v1:GetContractMetaDataLookUpRequest>
</soapenv:Body>
</soapenv:Envelope>
I need help mainly on how can i add that header info(as shown in above xml request) into soap header message.
help is greatly appreciated. thank you.
This should be saajSoapMessage.setSoapAction("GetMetaDataLookUpRequestType") instead of ((SoapMessage)soapMessage).setSoapAction("GetMetaDataLookUpRequestType").
I'm trying to parse a SOAP response from a web service. I'm using httpbuilder to do the request. Here is my code:
def String WSDL_URL = 'http://ws.webgains.com/aws.php'
def http = new HTTPBuilder( WSDL_URL , ContentType.XML )
String soapEnvelope =
"""<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<getFullUpdatedEarnings xmlns="http://ws.webgains.com/aws.php">
<startDate>2013</startDate>
<endDate>2013</endDate>
<username>username</username>
<password>pass</password>
</getFullUpdatedEarnings>
</soap12:Body>
</soap12:Envelope>"""
http.request( Method.POST, ContentType.XML ) {
body = soapEnvelope
response.success = { resp, xml ->
println "XML was ${xml.Body.getFullUpdatedEarningsResponse.return.text()}"
def territories = new XmlSlurper().parseText(
xml.Body.getFullUpdatedEarningsResponse.return.text()
)
}
response.failure = { resp, xml ->
xml
}
}
When I try to parse the response I get a org.xml.sax.SAXParseException Content is not allowed in prolog.
Here is the output I'm getting from the web services:
3936713759987www.tikcode.com1367552013-05-13T15:04:482013-05-13T15:04:48Miniinthebox - US46119566172850.060.8confirmednotcleared2013-05-13T14:58:33http%3A%2F%2Fwww.lightinthebox.com%2Fes%2F%3Flitb_from%3Daffiliate_webgainsEShttp%3A%2F%2Flocalhost%3A8080%2Fcom.publidirecta.widget%2Fpromocion%2FverPromocion%3Fpromocion%3D
If I use ContenTyp.TEXT the xml I'm getting is
[<?xml version="1.0" encoding="UTF-8"?>, <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn:http://ws.webgains.com/aws.php" xmlns:enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc"><ns1:getFullUpdatedEarningsResponse env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><rpc:result>return</rpc:result><return enc:itemType="ns1:fullLinesArray" enc:arraySize="1" xsi:type="ns1:fullReportArray"><item xsi:type="ns1:fullLinesArray"><transactionID xsi:type="xsd:int">39367137</transactionID><affiliateID xsi:type="xsd:int">59987</affiliateID><campaignName xsi:type="xsd:string">www.tikcode.com</campaignName><campaignID xsi:type="xsd:int">136755</campaignID><date xsi:type="xsd:dateTime">2013-05-13T15:04:48</date><validationDate xsi:type="xsd:dateTime">2013-05-13T15:04:48</validationDate><delayedUntilDate xsi:type="xsd:string"></delayedUntilDate><programName xsi:type="xsd:string">Miniinthebox - US</programName><programID xsi:type="xsd:int">4611</programID><linkID xsi:type="xsd:string">95661</linkID><eventID xsi:type="xsd:int">7285</eventID><commission xsi:type="xsd:float">0.06</commission><saleValue xsi:type="xsd:float">0.8</saleValue><status xsi:type="xsd:string">confirmed</status><paymentStatus xsi:type="xsd:string">notcleared</paymentStatus><changeReason xsi:nil="true"/><clickRef xsi:nil="true"/><clickthroughTime xsi:type="xsd:dateTime">2013-05-13T14:58:33</clickthroughTime><landingPage xsi:type="xsd:string">http%3A%2F%2Fwww.lightinthebox.com%2Fes%2F%3Flitb_from%3Daffiliate_webgains</landingPage><country xsi:type="xsd:string">ES</country><referrer xsi:type="xsd:string">http%3A%2F%2Flocalhost%3A8080%2Fcom.publidirecta.widget%2Fpromocion%2FverPromocion%3Fpromocion%3D</referrer></item></return></ns1:getFullUpdatedEarningsResponse></env:Body></env:Envelope>]
I'm fairly new to web services so If anyone have any ideas I really would appreciate any help
EDIT: Also tried with ws lite with the same results
It looks like you're parsing the response a second time. Why are you using an XmlSlurper to parse the text of the return tag? The elements under return are already parsed and can be accessed directly.
I want to use JAX-WS API to create a WS-Addressing enabled web service client. I used wsimport to create the client stub from the WSDL file, and can enable/disable WS-Addressing by using the AddressingFeature, e.g.
Hello hello = service.getHelloSoap11(new AddressingFeature(true, true));
However, I cannot find any samples in web that customize the WS-Addressing ReplyTo/FaultTo endpoint reference. Basically I want to create a WS request like the following (see the wsa:ReplyTo element):
<soapenv:Envelope ...>
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To soapenv:mustUnderstand="1">http://localhost:8080/poc/helloService/
</wsa:To>
<wsa:ReplyTo>
<wsa:Address>http://mycompany.com/poc/reply</wsa:Address>
<wsa:ReferenceParameters>
<field1 xmlns="http://mycompany.com/poc/cust">some value1</field1>
<field2 xmlns="http://mycompany.com/poc/cust">some value2</field2>
</wsa:ReferenceParameters>
</wsa:ReplyTo>
<wsa:Action>http://mycompany.com/poc/sayHello</wsa:Action>
<wsa:MessageID>urn:uuid:7849b04f-c74e-4836-99e4-8e25d2700fae
</wsa:MessageID>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
I can add endpoint reference if using Spring Web Service client. However, I need to do it using JAX-WS. Any ideas?
I answer my own question.
It seems that the standard JAX-WS API does not provide a convenient way to customize the WS-Addressing From/ReplyTo/FaultTo endpoint references. However, each JAX-WS runtime may provide additional proprietary API to set the headers.
For example, the IBM JAX-WS RI provides an EndpointReferenceManager SPI to create the endpoint reference:
import com.ibm.wsspi.wsaddressing.EndpointReference;
import com.ibm.wsspi.wsaddressing.EndpointReferenceManager;
import com.ibm.wsspi.wsaddressing.WSAConstants;
public void testWSAddressing () {
// get the port
Hello hello = service.getHelloSoap11();
// build a EndpiontReference of <wsa:ReplyTo>
BindingProvider bp = (BindingProvider) hello;
EndpointReference epr = EndpointReferenceManager.createEndpointReference(new URI(
"http://www.w3.org/2005/08/addressing/anonymous"));
epr.setReferenceParameter(new QName("http://mycompany.com/test", "someRefParam"),
"12345678");
((BindingProvider) hello).getRequestContext()
.put(WSAConstants.WSADDRESSING_REPLYTO_EPR, epr);
...
HelloResponse response = hello.hello(request);
}
The above code, when running inside IBM Websphere, will produce a SOAP message like the following:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>http://localhost:8080/poc/helloService/</wsa:To>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous
</wsa:Address>
<wsa:ReferenceParameters>
<someRefParam xmlns="http://mycompany.com/test">12345678</someRefParam>
</wsa:ReferenceParameters>
</wsa:ReplyTo>
<wsa:MessageID>urn:uuid:BE9E173A35BAB51CB31338454394298
</wsa:MessageID>
<wsa:Action>http://mycompany.com/Hello</wsa:Action>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope >
I've found a way to do this with standard JAX-WS.
When getting a port, use both AddressingFeature and OneWayFeature.
AddressingFeature addressingfeature = new AddressingFeature();
OneWayFeature onewayfeature = new OneWayFeature(true, new WSEndpointReference(YOUR_REPLY_TO_ADDRESS, AddressingVersion.W3C));
// get the port
Hello hello = service.getHelloSoap11(addressingfeature, onewayfeature);
This will produce messages with "ReplyTo" tag.
You may have to grab "com.sun.xml.ws:jaxws-rt" dependency for this.