Skip to main content

Problem with single port dual operation service and dispatch

2 replies [Last post]
steveor
Offline
Joined: 2006-03-02

Hi

Implementing my second jax-ws service now.
This time there is one port in the service but 2 operations.

Using same approach as my previous successful service I define my code as follows

I have checked that the client tns is equivalent to wsdl tns
Service and Port match the wsdl definitions also
and service appears deployed in glassfish, ie tester gives
correct results and wsdl is generated

public class CallAlarmService {
@WebServiceRef(wsdlLocation="http://localhost:8080/mtosi/v1/FaultService?wsdl")
/** Creates a new instance of CallAlarmService */

private final String NAMESPACEURI = "tmf854.v1.ws";
private static final String SERVICE_NAME = "FaultService";
private static final String PORT_NAME = "AlarmRetrieval";
private static final String OPERATION_NAME_1 = "getActiveAlarmsCount";
private static final String OPERATION_NAME_2 = "getActiveAlarms";
private QName SERVICE_QNAME = new QName(NAMESPACEURI, SERVICE_NAME);
private QName PORT_QNAME = new QName(NAMESPACEURI, PORT_NAME);

SOAPMessage resMsg;
FaultService fService = new FaultService();

Dispatch dispatchMsg = null;
//webendpoint = port in wsdl file
@WebEndpoint(name = "AlarmRetrieval")
public SOAPMessage getCount(SOAPMessage reqMsg) {
try
{

dispatchMsg = fService.createDispatch(PORT_QNAME, SOAPMessage.class, javax.xml.ws.Service.Mode.MESSAGE);
resMsg = dispatchMsg.invoke(reqMsg);
}
catch (Exception e)
{
System.out.println("Exception Thrown in getCount");
e.printStackTrace();
}
return resMsg;
}

@WebEndpoint(name = "AlarmRetrieval")
public SOAPMessage getAlarms(SOAPMessage reqMsg) {
try
{

dispatchMsg = fService.createDispatch(PORT_QNAME, SOAPMessage.class, javax.xml.ws.Service.Mode.MESSAGE);

resMsg = dispatchMsg.invoke(reqMsg);
}
catch (Exception e)
{
System.out.println("Exception Thrown in getAlarms");
e.printStackTrace();
}
return resMsg;
}

}

When I call the web service I get 404, I suspect this is because I'm not specifying an operation but the only annotation that includes operation is web method (I assume this was only for the service implementation)

for info the operations are defined as follows in the wsdl

regards
steve

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
steveor
Offline
Joined: 2006-03-02

Found out what caused the 404 but still a bit puzzled

The Request URI (as noticed on HTTP monitor) was set incorrectly to /

(My service is deployed at / since I set the servicename annotation to put it there.)

On the client, looking in debugger the dispatch _portinfo targetEndpoint was being set to /

It turns out it was reading the soap:address location from the local wsdl file to do the POST request - changing the soap:address to match the deployed web service fixed the problem.

The bit that puzzles me is that my other web service works fine without having to change the soap:address

I am using the following in my client, the first ignores the wsdl when doing a post whereas the second reads the wsdl (going wsdl2java by the way)

public class CallNotificationService {
@WebServiceRef(
wsdlLocation="http://localhost:8080/mtosi/v1/NotificationService?wsdl"
)

public class CallAlarmService {
@WebServiceRef(wsdlLocation="http://localhost:8080/mtosi/v1/FaultService?wsdl")

I set my endpoint as follows
@WebEndpoint(name = PORT_NAME)

Any idea why the WebServiceRef is not being used when posting the soap message?

regards
Steve

steveor
Offline
Joined: 2006-03-02

PS

Setting the correct XmlRootElement in the request message
magically allows the correct operation method to be found on
the port - if the wrong case is used then you get the strange 500 error (glassfish bug 527). I just checked the
expected XmlRootElement from the Tester page and it worked

Still puzzled about the request URI question though?

regards
Steve