I am new to SOAP and POSTMAN and am wondering what I am doing wrong with the following. I have a sample java webservice using jax-ws:
@WebService(endpointInterface = "Soap1.SOAPInterface")
public class SOAPService implements SOAPInterface
{
public String message(String name)
{
return "Hello " + name;
}
}
I published this webservice using an Endpoint:
public class Publisher
{
public static void main(String[]args)
{
Endpoint.publish("http://localhost:9006/Service", new SOAPService());
}
}
Now when I run this in a client it works fine
public static void main(String[] args) throws Exception
{
URL url = new URL("http://localhost:9006/Service?wsdl");
QName qname = new QName("http://Soap1/","SOAPServiceService");
Service s = Service.create(url,qname);
SOAPInterface i = s.getPort(SOAPInterface.class);
System.out.println(i.message("Bob"));
}
However when trying to use POSTMAN to analyze SOAP request/responses. By entering the following xml for a request:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<MyMessage xmlns="http://Soap1/">
<name>Bob</name>
</MyMessage>
</Body>
</Envelope>
I get a response of Hello null
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:MyMessageResponse xmlns:ns2="http://Soap1/">
<returnedMessage>Hello null</returnedMessage>
</ns2:MyMessageResponse>
</S:Body>
</S:Envelope>
I am wondering why this is because using the client, the parameters are passing fine but when using POSTMAN they seem not to be passing.
If you open in browser URI http://localhost:9006/Service?wsdl, you'll see WSDL generated by JAX-WS for your service. It should contain following snippet:
<types>
<xsd:schema>
<xsd:import namespace="http://example.soap.kdv.org/" schemaLocation="http://localhost:9006/Service?xsd=1"/>
</xsd:schema>
</types>
It contains reference to XML schema defining structure of XML messages used in web-service. If you open URI http://localhost:9006/Service?xsd=1 as well (URI can differ, please check it), you'll see definition of request and response message:
<xs:schema xmlns:tns="http://example.soap.kdv.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://example.soap.kdv.org/">
<xs:element name="message" type="tns:message"/>
<xs:element name="messageResponse" type="tns:messageResponse"/>
<xs:complexType name="message">
<xs:sequence>
<xs:element name="arg0" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="messageResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
It defines following structure of request message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:exam="http://example.soap.kdv.org/">
<soapenv:Header/>
<soapenv:Body>
<exam:message>
<!--Optional:-->
<arg0>test</arg0>
</exam:message>
</soapenv:Body>
</soapenv:Envelope>
Try this message in postman, it should return you desired result.
Also I'd like to recommend SOAP UI tool for testing web services. When creating new SOAP project in this tool, it imports WSDLs and generates for you request messages.