SOAP Action using ksoap2 - soap

I'm trying to make a call to one SOAP Webservice that WSDL file looks something like this:
<wsdl:service name="API">
<wsdl:port binding="tns:API" name="API">
<soap:address location="https://secure.server.com/clients/api/api.php"/>
</wsdl:port>
</wsdl:service>
I'm using ksoap2 library for Android. What is the SOAP Action value that I should use to make a call?
Thanks

It depends if you are using the RPC/literal or Document/literal type for your WSDL file.
- For RPC/literal you should specify the method name which is the name of the function you call on the WS. So the action is in fact the method name.
- For Document/literal the method is not specified in the XML of the request. So action is null or empty String
I strongly recommend you to use the type RPC/literal (see differences here: http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/) if you are the WS developer If not, check the type and do according to this.
So if it is RPC/literal the SOAP Action is the method name you are calling on your WS.

Related

camel cxfrs put with path param overrides payload

I develop a rest endpoint in camel and would like to provide the following PUT - Method /service/createObject/{objectId} which also accepts a payload.
If I configure a mehtod like this, the payload will be overridden with the path parameter {objectId}. Is that the default behaviour and can I change it?

What is the difference between BasicHttpRequest and HttpGet, HttpPost, etc in Apache HTTP Client 4.3 ?

I am creating HTTP request using Apache HTTP Client version 4.3.4. I see there are some classes like HttpGet,... and there is also a class BasicHttpRequest. I am not sure which one to use.
Whats the difference and which one should be used in which condition ?
BasicHttpRequest is provided by the core library. As its name suggests it is pretty basic: it enforces no particular method name or type, nor does it attempt to validate the request URI. The URI parameter can be any arbitrary garbage. HttpClient will dutifully transmit it to server as is, if it is unable to parse it to a valid URI.
HttpUriRequest variety on the other hand will enforce specific method type and will require a valid URI. Another important feature is that HttpUriRequest can be aborted at any point of their execution.
You should always be using classes that implement HttpUriRequest per default.
I was just browsing the 4.3.6 javadoc attempting to locate your BasicHttpRequest and was unable to find it. Do you have a reference to the javadoc of this class?
I would be under the impression that BasicHttpRequest would be a base class providing operations and attributes common to more than one HttpRequest. It may be extremely generic for extension purposes.
To the first part of your question, use HttpGet, HttpPost etc for their specific operations. If you only need to HTTP/GET information then use HttpGet, if you need to post a form or document body, then use HttpPost. If you are attempting to use things like the Head, Put, Delete method, then use the correspoding HttpXXX class.

CXF: Implement multiple ports on same soap:adress?

We got a WSDL from a client, asking us to implement the service on our side.
The WSDL contains 3 port-bindings, with different names and bindings, but identical <soap:adress> --- like this:
<port name="Name1" binding="tns:Binding1">
<soap:address location="http://localhost/Service/ServicePort" />
</port>
<port name="Name2" binding="tns:Binding2">
<soap:address location="http://localhost/Service/ServicePort" />
</port>
<port name="Name3" binding="tns:Binding3">
<soap:address location="http://localhost/Service/ServicePort" />
</port>
Is such WSDL possible to implement with CXF?
When I run wsdl2java, CXF generates 3 java-interfaces.
I first tried a single implementation-class, like
class MyServiceClass implements Interface1, Interface2, Interface3 {...}
But when I deployed it and checked with SoapUI, for some reason,
it would only expose Port-binding for Interface1,
and seemed to ignore the 2 other ones. Why?
I then tried instead, to implement 3 different ServiceClasses (each implementing one of the interfaces),
then put multiple <jaxws:endpoint> with identical address attributes in cxf-config.xml
But I then get deployment-error:
RuntimeException: Soap 1.1 endpoint already registered on address /Address
Any hints, how to implement such WSDL in CXF?
Is it possible?
But when I deployed it and checked with SoapUI, for some reason, it would only expose Port-binding for Interface1, and seemed to ignore the 2 other ones. Why?
If you will see your implementation class, you will find this annotation,
#WebService(endpointInterface = "yourPackageName.Interface1")
Which is referring to your interface1 only. That's why on deploying it is ignoring rest 2 interface implementations.
So, you have to implement these 3 interface separately in different implemenataion class as you did as per your explanantion. Because only one endpointInterface is allowed in each implementation class.
Is such WSDL possible to implement with CXF?
Yes, it is possible.
During the deployement in your endpoint publisher class, you need to wrap these 3 interface implementation class object in one object and publish for a single end point.
I am still not clear how to do that, ill update the answer later.
Few useful links: It's same requirement but little confusing.
http://cxf.547215.n5.nabble.com/Deploying-multiple-endpoints-ports-for-a-service-td569470.html
Also read about JavaBeans endpoint implementation , i think in this case, it will be more easier than this.

Understanding WSDL's, SOAP, REST, etc

I'm trying to learn how to use WSDL's to call web services from a Grails project. I've been provided with the WSDL and some XML results for reference.
I've been able to generate Java code from the WSDL, and everything seems to be working correctly.
Here's the WSDL: http://www.restfulwebservices.net/rest/USAZipCodeService.svc?wsdl
And here is the XML: http://api.geonames.org/postalCodeSearch?placename=MN&username=demo
I am receiving this exception in my project:
ERROR client.WebServiceClientFactoryImpl$WSClientInvocationHandler - No namespace on "geonames" element.
javax.xml.ws.soap.SOAPFaultException: No namespace on "geonames" element.
It seems like it is saying that the XML returned isn't valid for SOAP? Am I missing/misunderstanding some pieces the puzzle here? It is all pretty new to me.
Edit:
I am trying to use a Grails plugin called cxf client: https://github.com/ctoestreich/cxf-client
It is configured with the following in Config.groovy (something could be wrong/missing here?):
wsdl = "http://www.restfulwebservices.net/wcf/USAZipCodeService.svc?wsdl"
namespace = "cxf.client.postalcode"
clientInterface = "cxf.client.postalcode.IPostalCodeService"
serviceEndpointAddress = "http://api.geonames.org/postalCodeSearch"
I guess you just sent the XML returned from http://api.geonames.org/postalCodeSearch?placename=MN&username=demo as a parameter to the web service. Obviously, from the WSDL description returned you can see there is no such element named geonames, so the SOAPFaultException exception is quite a fair result.
To fix it, you have to refer to the WSDL description carefully, to make sure the invoke method has the right parameters work with whatever defined in the USAZipCodeService WSDL description tags like <wsdl:operation> and <wsdl:message>.
Another issue: 2 different WSDLs were metioned in your invoker and Config.groovy. The former is a RESTful service, and the later is a SOAP one. They work with different invoke methods and parameters, so make sure your code has consistent invoker and parameters, too.

Convert a WSDL to its respective HTTP Bindings

I'm simply trying to convert a WSDl into a number of different HTTP-requests from data supplied by the WSDL. I have read through a ton of similar questions, but none really provided an answer.
Some say to use SOAPUI - I am familiar with this application and do use it. But I need to create these HTTP-requests from the WSDL on my own.
Some say to try JAXWS - I looked at a number of tutorials on this as well as on Axis and these translate the WSDL into Java class bindings and you use those methods to test the web services. I really would like to just generate the HTTP-request myself so that at one point I can manipulate the request and send my own tests.
I started using wsdl4j to begin parsing the WSDL myself but would rather not go down this path until I'm absolutely sure I'm not reinventing the wheel. Seems to me there has been a need for this in past? But with WSDL4J and every other library I do not see a WSDL to Soap message translation.
Any suggestions would be very helpful. The goal is I want to be able to take a WSDL, examine it and create HTTP-SOAP requests for each method in the WSDL and be able to than test them for security issues. The first step is to create those requests!
When calling a SOAP web service you can use a static invocation or a dynamic invocation.
Static invocation means creating a stub from the WSDL and using that to perform the call. This creates all the "plumbing" code for you, but is tightly tied to just that web service and you can't use it for other web services with different contracts. For each WSDL you need to create another stub.
With dynamic invocation, you read the WSDL at runtime and figure out how to call the web service based on the info you get from the WSDL. Feed it multiple WSDLs and the client adapts.
The dynamic invocation is what SoapUI uses to generate the sample requests and responses.
It reads the WSDL you feed it, extracts the XML schema from the types section and generates XML instances. To do so, it uses Wsdl4j and XmlBeans under the hood.
Your decision to use Wsdl4j is good as it gives you control when parsing the WSDL. But also have a look at XmlBeans; it has some other tools you might find useful, like the schema to instance class for example.
If you need to see it in action (maybe debug it to see what's going on) you could create a quick dirty test with the SoapUI API:
import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;
public class Test {
public static void main(String[] args) throws Exception {
WsdlProject project = new WsdlProject();
WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://www.html2xml.nl/Services/Calculator/Version1/Calculator.asmx?wsdl");
WsdlInterface wsdl = wsdls[0];
System.out.println(wsdl.getOperationByName("Add").createRequest(true));
System.exit(0); // just to clear up some threads created by the project
}
}
The message you should see printed (for the Add operation of the Calculator WS) would be something like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Add>
<tem:a>?</tem:a>
<tem:b>?</tem:b>
</tem:Add>
</soapenv:Body>
</soapenv:Envelope>
Hope this helps you move beyond the first step.