开发者

Java consuming a webservice

I've been asked to rebuild our customer portal, using gwt and connecting to our data using various webservices set up on the server.

I generated all the proxy classes usign the WSDL and Jax-WS/wsimport utility, however when i make the below call:

ReportingApiSoap soap = api.getReportingApiSoap();      
ArrayOfReport returnValues = soap.getReports(serverCredentials, true);

My returnValues object is null. I know the webservice itself works because I was able to test it with the same parameters I'm passing in now.

I was previously have some issues sending data to the webservice; that turning out to be the namespaces weren't lining up as they needed to. I suspect something similar is happening here, but haven't been able to figure out what yet.

Anyone ever run into something similiar before? Or if not any idea how I can check the raw xml I'm getting out of the webservice call? That way I can track the problem a step furthur.

-Ian

My Credentials object:

public class ApiCredentials {

 @XmlElement(name = "Id", namespace="http://mycompany.com")
 protected String id;
 @XmlElement(name = "Login", namespace="http://mycompany.com")
 protected String login;
 @XmlElement(name = "Password", namespace="http://mycompany开发者_如何学Python.com")
 protected String password;

 ...
}

ArrayofReport:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfReport", propOrder = {
 "report"
})
public class ArrayOfReport {

 @XmlElement(name = "Report", nillable = true)
 protected List<Report> report;

 public List<Report> getReport() {
    if (report == null) {
        report = new ArrayList<Report>();
    }
    return this.report;
 }

}

Webservice call:

@WebMethod(operationName = "GetReports", action = "http://mycompany.com/GetReports")
@WebResult(name = "GetReportsResult", targetNamespace = "http://mycompany.com")
@RequestWrapper(localName = "GetReports", targetNamespace = "http://mycompany.com", className = "com.mycompany.customerportal.server.GetReports")
@ResponseWrapper(localName = "GetReportsResponse", targetNamespace = "http://mycompany.com", className = "com.mycompany.customerportal.server.GetReportsResponse")
public ArrayOfReport getReports(
    @WebParam(name = "credentials", targetNamespace = "http://mycompany.com")
    ApiCredentials credentials,
    @WebParam(name = "includeFields", targetNamespace = "http://mycompany.com")
    boolean includeFields);


I recommend creating a mock web service (e.g. using soapUI). This will allow you to see and validate the request XML against your WSDL. You can cut'n'paste/edit mock responses to the client to see the effect.

JAX-WS implementations are a dime-a-dozen, so any further options depend on the client technology in your runtime. I would ensure that validation is enabled (this might be implemented as a feature, for example).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜