1

Hi I am new to Web Services, I have the requirement of Code First Approach,

I have an interface like below

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);

}

I want to expose an implementation if the the above interface as web service.

The implementation class is as below:

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;
}
}

To expose this service as web service I am using JDK's EndPoint class as below.

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..!");

} 
}

But When I run the server program I am getting the following exception.

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

Here in StockQuoteService interface and corresponding implementation I have two overloaded update method one is taking two parameters while other is taking three.

If I change second update method name to different name, then the server is running fine without exception.

But exception is coming when i have overloaded update methods only.

Even though I kept overloaded methods, their operation names and corresponding soap actions are different, you can see them in annotations on top of the methods.

Any help will give me great relief and appreciated as well.

Jagadeesh
  • 862
  • 7
  • 23
  • Please refer to this thread about overloading web-service methods: [Can we implement method overloading in web service class?][1] [1]: http://stackoverflow.com/questions/10320006/can-we-implement-method-overloading-in-web-service-class – owenrb Mar 04 '15 at 11:13
  • Operation Overload is not supported in webservice https://stackoverflow.com/questions/4519643/webservice-method-overloading – Asy Mar 06 '15 at 10:32

0 Answers0