您好我是Web Services的新手,我有Code First Approach的要求,
我有一个如下界面
package in.co.way2learn;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService(name="SQS",portName="SQSP",serviceName="SQSS")
public interface StockQuoteService {
@WebMethod(operationName="getPrice")
public double getPrice(@WebParam(name="symbol")String symbol);
@WebMethod(operationName="aaa",action="aaaAction")
public boolean update(@WebParam(name="sybmol")String symbol,@WebParam(name="price")double price);
@WebMethod(operationName="bbb",action="bbbAction")
public boolean update(@WebParam(name="sybmol")String symbol,@WebParam(name="price")double price,@WebParam(name="flag")boolean flag);
}
如果将上述接口作为Web服务,我想公开一个实现。
实施类如下:
package in.co.way2learn;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService(name="SQSI",
endpointInterface="in.co.way2learn.StockQuoteService",
portName="SQSIP",serviceName="SQSIS")
public class StockQuoteServiceImpl implements StockQuoteService{
@Override
public double getPrice(String symbol) {
System.out.println("StockQuoteServiceImpl.getPrice()");
return 123;
}
@Override
@WebMethod(operationName="aaa",action="aaaAction")
public boolean update(String symbol, double price) {
System.out.println("StockQuoteServiceImpl.update()");
return true;
}
@Override
@WebMethod(operationName="bbb",action="bbbAction")
public boolean update(String symbol, double price, boolean flag) {
System.out.println("StockQuoteServiceImpl.update()");
return true;
}
}
要将此服务公开为Web服务,我使用的是JDK的EndPoint
类,如下所示。
package in.co.way2learn;
import javax.xml.ws.Endpoint;
public class Server {
public static void main(String[] args) {
StockQuoteService stockQuoteService=new StockQuoteServiceImpl();
String address="http://localhost:8080/sqs";
Endpoint.publish(address, stockQuoteService);
System.out.println("Server started..!");
}
}
但是当我运行服务器程序时,我得到以下异常。
Exception in thread "main" javax.xml.ws.WebServiceException: class in.co.way2learn.jaxws.Update do not have a property of the name flag
at com.sun.xml.internal.ws.server.sei.EndpointArgumentsBuilder$DocLit.<init>(Unknown Source)
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.createArgumentsBuilder(Unknown Source)
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.<init>(Unknown Source)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.<init>(Unknown Source)
at com.sun.xml.internal.ws.server.EndpointFactory.createEndpoint(Unknown Source)
at com.sun.xml.internal.ws.api.server.WSEndpoint.create(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.createEndpoint(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(Unknown Source)
at javax.xml.ws.Endpoint.publish(Unknown Source)
at in.co.way2learn.Server.main(Server.java:10)
Caused by: javax.xml.bind.JAXBException: flag is not a valid property on class in.co.way2learn.jaxws.Update
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getElementPropertyAccessor(Unknown Source)
... 11 more
在StockQuoteService
接口和相应的实现中,我有两个重载update
方法,一个是两个参数,而另一个是三个。
如果我将第二个update
方法名称更改为其他名称,那么服务器运行正常,毫无例外。
但是当我仅重载update
方法时会出现异常。
即使我保留了重载方法,它们的操作名称和相应的soap操作也不同,您可以在方法之上的注释中看到它们。
任何帮助都会让我感到非常欣慰和欣赏。