java wsdl asmx 替换_如何从java调用Web服务(由wsdl描述)

JDK 6带有jax-ws,开发Web服务客户端所需的一切。

C:\temp> md generated

C:\temp>"c:\Program Files\Java\jdk1.6.0_17"\bin\wsimport -keep -d generated http://www50.brinkster.com/vbfacileinpt/np.asmx?wsdl

创建如下所示的PrimeClient.java:

import javax.xml.ws.WebServiceRef;

import com.microsoft.webservices.*;

//the above namespace is from the generated code from the wsdl.

public class PrimeClient {

//Cant get this to work.. @WebServiceRef(wsdlLocation="http://www50.brinkster.com/vbfacileinpt/np.asmx?wsdl")

static PrimeNumbers service;

public static void main(String[] args) {

try {

service = new PrimeNumbers();

PrimeClient client = new PrimeClient();

client.doTest(args);

} catch(Exception e) {

e.printStackTrace();

}

}

public void doTest(String[] args) {

try {

System.out.println("Retrieving the port from the following service: " + service);

PrimeNumbersSoap pm = service.getPrimeNumbersSoap();

System.out.println("Invoking the getPrimeNumbersSoap operation ");

System.out.println(pm.getPrimeNumbers(100));

} catch(Exception e) {

e.printStackTrace();

}

}

}

编译并运行:

C:\temp>"c:\Program Files\Java\jdk1.6.0_17"\bin\javac -cp generated PrimeClient.java

C:\temp>"c:\Program Files\Java\jdk1.6.0_17"\bin\java -cp .;generated PrimeClient

Retrieving the port from the following service: com.microsoft.webservices.PrimeN

umbers@19b5393

Invoking the getPrimeNumbersSoap operation

1,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97

你可能感兴趣的:(java,wsdl,asmx,替换)