Click to See Complete Forum and Search --> : How to use Java call WS created by .NET
noomyai
06-15-2006, 09:06 PM
How can I use Java to call web services that created by .NET? Your example code is appreciated.
Below is an example for SOAP request:
POST /myservices/fisservice.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/MYServices/MYServices/GageRR"
<?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>
<GageRR xmlns="http://tempuri.org/MYServices/MYServices">
<XMLInput>string</XMLInput>
</GageRR>
</soap:Body>
</soap:Envelope>
chazzy
06-15-2006, 11:02 PM
there should be a wsdl associated w/ this. you typically want to use a WSDL2Java setup to convert the wsdl's objects to java classes. it'll include a service locator for farm setups as well. I've been tinkering with the axis2 wsdl2java convertor plugin for eclipse lately, but i prefer a different setup, it uses a ton of external jar's and ibm's original wsdl2java.
noomyai
06-21-2006, 03:29 AM
Got it works now. Just want to share my experience.
Tools: jdk-1.4.x, Axis-1.4, Eclipse-3.1.2, JBoss-4.0.3
1. Create new java project. (using Eclipse IDE)
2. Add required libraries. All Axis libraries, activation.jar and mail.jar from JBoss.
3. Create ant build.xml file. Edit content wsdl url link.
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="all" name="generate_wsclient_stub">
<property name="axis.home" value="d:/apache/axis/lib"/>
<path id="axis.classpath">
<fileset dir="${axis.home}">
<include name="**/*.jar"/>
</fileset>
</path>
<taskdef resource="axis-tasks.properties" classpathref="axis.classpath"/>
<!-- ant calls to call when executed -->
<target name="all">
<antcall target="generate_stub"/>
</target>
<!-- directory where to generate the code -->
<property name="generated.client.dir" value="./src"/>
<!-- definition of the web service from code is generated -->
<!-- the value can be wsdl file or wsdl url -->
<property name="service.wsdl" value="http://localhost/service/HelloWorld.asmx?wsdl"/>
<!-- generate client stub for SABLE service -->
<target description="generate the java sources for the client" name="generate_stub">
<axis-wsdl2java output="${generated.client.dir}" url="${service.wsdl}" verbose="true"/>
</target>
</project>
4. Compile ant build. This step will get 4 Java class files.
5. Create new Java class
package ws.app.client;
import ws.app.HelloWorldLocator;
import ws.app.HelloWorldSoap;
public class SoapClient {
public static void main(String[] args) {
try {
HelloWorldLocator loc = new HelloWorldLocator();
HelloWorldSoap port = loc.getHelloWorldSoap();
System.out.println(port.sayHelloWorld());
System.out.println(port.addNumber(15, 10));
}
catch(Exception e) {
System.out.println(e.getMessage());
}
}
}