Reputation: 454
I'm trying to create a Java spring web service using cxf. I'm taking the (bottom up) approach of taking Java contracts and annotating the code to generate the web service.
Given the following annotated Web interface code.
WebInterface:
package org.webservice;
import java.util.ArrayList;
import java.util.Calendar;
import javax.jws.WebMethod;
@WebService
public interface WebInterfaceI {
@WebMethod(operationName = "writeXML")
public String writeStuff(String objectType, String payloadXML,
String callerInfo, String options);
@WebMethod(operationName = "XML")
public ArrayList<String> readStuff(KeyValuePair Data, Calendar asOfDate,
KeyValuePair options);
}
The writeStuff() function is exposed in the WSDL just fine.
The readStuff() method passes a complex types called KeyValuePair (not a great name I know). These are defined in a separate file (though I have tried to make it a local class too).
KeyValuePair class:
package org.webservice;
import java.io.Serializable;
import java.util.List;
import javax.jws.WebService;
public class KeyValuePair implements Serializable {
private static final long serialVersionUID = 1L;
KeyValuePair() {
myValues = null;
myKeys = null;
}
KeyValuePair(List<String> keys, List<String> values) {
myValues = values;
myKeys = keys;
}
List<String> myValues;
List<String> myKeys;
}
But in the WSDL the KeyValuePair is simply listed as a complex type. So When I point a .Net4 Service Reference at the WSDL the code which is generated treats the KeyValuePair as an object.
Generated .Net client code:
public partial class keyValuePair: object, System.ComponentModel.INotifyPropertyChanged {
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
The members of the KeyValuePair are not exposed so it's not possible to populate one on the client.
So the questions is:
Is what I'm trying to do actually possible?
Is there an easy way to expose the KeyVlauePair (what I believe is called a Data Contract) via the WSDL using annotations?
Or does it habve to be done an alternative way (by specifying a XSD file the KeyValuePair somehow?)
I'm using:
Spring tools suite 2.9.2
cxf 2.6.1
.Net 4 via VS 2010.
Upvotes: 1
Views: 1132
Reputation: 1388
Hi @DUFF maybe that not you be populate KeyValuePair object into WEB Service you can try something like this on KeyValuePair class,
public class KeyValuePair implements Serializable {
private static final long serialVersionUID = 1L;
List<String> myValues;
List<String> myKeys;
public KeyValuePair(List<String> keys, List<String> values) {
this.myKeys = keys;
this.myValues = values;
}
public List<String> getMyValues() {
return myValues;
}
public void setMyValues(List<String> myValues) {
this.myValues = myValues;
}
public List<String> getMyKeys() {
return myKeys;
}
public void setMyKeys(List<String> myKeys) {
this.myKeys = myKeys;
}
}
And before you may populate KeyValuePair object for WSDL file exposed.
Hope these helps. :)
Upvotes: 1