java.lang.IllegalArgumentException:webservices.CurrencyConversion不是接口

时间:2018-03-31 06:06:54

标签: web-services jsf webservice-client managed-bean

我在JSF项目中构建了一个简单的Web服务。我已经测试了我用java应用程序创建的Web服务,它的工作正常。之后,我尝试将Web服务中的方法调用到我的managedBean以使用jsf。如下发生异常:

javax.faces.el.EvaluationException: java.lang.IllegalArgumentException: webservices.CurrencyConversion is not an interface
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)

这是我的网络服务代码:

package webservices;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

@WebService(serviceName = "CurrencyConversion")
public class CurrencyConversion {

String listCurrency[] = {"MYR", "EUR", "USD", "SGD", "AUD", "HKD", "CNY", "TWD"};
double listRate[] = {0.258667, 1.22903, 1.000000, 0.762768, 0.766570, 0.127416, 0.159005, 0.0343023};

String origin = null;
String destination = null;
double oriRate;
double destRate;
double convertRate;
double amount = 1.0;

@WebMethod(operationName = "convertCurrency")
public double convertCurrency(@WebParam(name = "origin") String origin,@WebParam(name = "destination") String destination) {

    double convertRate = 0.0;

    for (int i = 0; i < listCurrency.length; i++){
        if (origin.equals(listCurrency[i])) {
            oriRate = listRate[i];
            i = i + listCurrency.length;
        }
    }

    for (int i = 0; i < listCurrency.length; i++){
        if (destination.equals(listCurrency[i])) {
            destRate = listRate[i];
            i = i + listCurrency.length;
        }
    }

    convertRate = amount * (oriRate / destRate);

    return convertRate;

}

}

这是我调用Web服务方法的方式:

String origin = null;
String destination =null;
double convertRate = 0.0;

public String getOrigin() {
    return origin;
}

public String getDestination() {
    return destination;
}

public void setOrigin(String origin) {
    this.origin = origin;
}

public void setDestination(String destination) {
    this.destination = destination;
}

public double getConvertRate() {
    return convertRate;
}

public void setConvertRate(double convertRate) {
    this.convertRate = convertRate;
}

public void convert() {
    convertRate = convertCurrency(origin, destination);
}

private double convertCurrency(java.lang.String origin, java.lang.String destination) {
    // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe.
    // If the calling of port operations may lead to race condition some synchronization is required.
    webservices.CurrencyConversion port = service.getCurrencyConversionPort();
    return port.convertCurrency(origin, destination);
}

最后我写的是jsf:              

        <h:selectOneMenu value = "#{courseworkBean.origin}" class="listbox"> 
            <f:selectItem itemValue = "MYR" itemLabel = "MYR" />
            <f:selectItem itemValue = "EUR" itemLabel = "EUR" />
            <f:selectItem itemValue = "USD" itemLabel = "USD" />
            <f:selectItem itemValue = "SGD" itemLabel = "SGD" /> 
            <f:selectItem itemValue = "AUD" itemLabel = "AUD" /> 
            <f:selectItem itemValue = "HKD" itemLabel = "HKD" /> 
            <f:selectItem itemValue = "CNY" itemLabel = "CNY" />
            <f:selectItem itemValue = "TWD" itemLabel = "TWD" />
        </h:selectOneMenu>

        <h:selectOneMenu value = "#{courseworkBean.destination}" class="listbox"> 
            <f:selectItem itemValue = "MYR" itemLabel = "MYR" />
            <f:selectItem itemValue = "EUR" itemLabel = "EUR" />
            <f:selectItem itemValue = "USD" itemLabel = "USD" />
            <f:selectItem itemValue = "SGD" itemLabel = "SGD" /> 
            <f:selectItem itemValue = "AUD" itemLabel = "AUD" /> 
            <f:selectItem itemValue = "HKD" itemLabel = "HKD" /> 
            <f:selectItem itemValue = "CNY" itemLabel = "CNY" />
            <f:selectItem itemValue = "TWD" itemLabel = "TWD" />
        </h:selectOneMenu>

        <h:commandButton class="cmdbutton" value = "Submit" action = "#{courseworkBean.convert()}" />

        <h:outputText value="#{courseworkBean.getConvertRate()}" />

    </h:form>
</h:body>

我试图找到几种解决方案,但对我来说没有任何效果。请告诉我我的代码有什么问题,谢谢。

0 个答案:

没有答案