我已使用wsimport将 WSDL 文件转换为 java
它生成两个文件
计算器
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.ws.Action;
@WebService(name = "ICalculator", targetNamespace = "http://ws.test.ews/")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface ICalculator {
/**
*
* @param arg2
* @param arg1
* @param arg0
* @return
* returns int
*/
@WebMethod(operationName = "PerformCalculation")
@WebResult(partName = "return")
@Action(input = "http://ws.test.ews/ICalculator/PerformCalculationRequest", output = "http://ws.test.ews/ICalculator/PerformCalculationResponse")
public int performCalculation(
@WebParam(name = "arg0", partName = "arg0")
int arg0,
@WebParam(name = "arg1", partName = "arg1")
int arg1,
@WebParam(name = "arg2", partName = "arg2")
String arg2);
}
CalculatorImplService
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
@WebServiceClient(name = "CalculatorImplService", targetNamespace = "http://ws.test.ews/", wsdlLocation = "http://localhost:9998/ws/calculator?wsdl")
public class CalculatorImplService
extends Service
{
private final static URL CALCULATORIMPLSERVICE_WSDL_LOCATION;
private final static WebServiceException CALCULATORIMPLSERVICE_EXCEPTION;
private final static QName CALCULATORIMPLSERVICE_QNAME = new QName("http://ws.test.ews/", "CalculatorImplService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("http://localhost:9998/ws/calculator?wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
CALCULATORIMPLSERVICE_WSDL_LOCATION = url;
CALCULATORIMPLSERVICE_EXCEPTION = e;
}
public CalculatorImplService() {
super(__getWsdlLocation(), CALCULATORIMPLSERVICE_QNAME);
}
public CalculatorImplService(WebServiceFeature... features) {
super(__getWsdlLocation(), CALCULATORIMPLSERVICE_QNAME, features);
}
public CalculatorImplService(URL wsdlLocation) {
super(wsdlLocation, CALCULATORIMPLSERVICE_QNAME);
}
public CalculatorImplService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, CALCULATORIMPLSERVICE_QNAME, features);
}
public CalculatorImplService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public CalculatorImplService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
/**
*
* @return
* returns ICalculator
*/
@WebEndpoint(name = "CalculatorImplPort")
public ICalculator getCalculatorImplPort() {
return super.getPort(new QName("http://ws.test.ews/", "CalculatorImplPort"), ICalculator.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns ICalculator
*/
@WebEndpoint(name = "CalculatorImplPort")
public ICalculator getCalculatorImplPort(WebServiceFeature... features) {
return super.getPort(new QName("http://ws.test.ews/", "CalculatorImplPort"), ICalculator.class, features);
}
private static URL __getWsdlLocation() {
if (CALCULATORIMPLSERVICE_EXCEPTION!= null) {
throw CALCULATORIMPLSERVICE_EXCEPTION;
}
return CALCULATORIMPLSERVICE_WSDL_LOCATION;
}
}
现在我想在 JSF 中调用这个 WEB SERVICE。页面(JSF)发送三个参数并获得结果。
JSF 页面
<h:body>
<h3>Calculator</h3>
<h:form>
<h:inputText value="#{?}"></h:inputText> //for @para1
<h:inputText value="#{?}"></h:inputText> //for @para2
<h:inputText value="#{?}"></h:inputText> //for @para3
<h:commandButton value="Calculate" action="?"></h:commandButton>
</h:form>
<h:panelGroup">
<h4>Results</h4>
<table>
<tr><td>${?}</td></tr>
</table>
</h:panelGroup>
</h:body>
我可以@ManagedBean
@SessionScoped
在 CalculatorImplService 中使用吗?让我知道!
如何在 JSF 中调用此 Web 服务?