Hi,
I'm trying to programm a webservice in java. For I'm new to the area of webservices I downloaded netbeans and just started. so my webservice looks that way:
@WebService()
public class HuntGameWS {
private DatabaseHandler m_dbHandler;
public HuntGameWS()
{
try {
m_dbHandler = new DatabaseHandler();
} catch (ClassNotFoundException ex) {
Logger.getLogger(HuntGameWS.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(HuntGameWS.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* Web service operation
*/
@WebMethod(operationName = "checkUserNameExists")
public boolean checkUserNameExists(@WebParam(name = "strUserName")
String strUserName) {
try {
if( m_dbHandler == null )
m_dbHandler = new DatabaseHandler();
return m_dbHandler.checkUserNameExists(strUserName);
} catch (ClassNotFoundException ex) {
Logger.getLogger(HuntGameWS.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(HuntGameWS.class.getName()).log(Level.SEVERE, null, ex);
}
return true;
}
/**
* Web service operation
*/
@WebMethod(operationName = "checkEmailExists")
public boolean checkEmailExists(@WebParam(name = "strEmail")
final String strEmail) {
try {
if( m_dbHandler == null )
m_dbHandler = new DatabaseHandler();
return m_dbHandler.checkEmailExists(strEmail);
} catch (ClassNotFoundException ex) {
Logger.getLogger(HuntGameWS.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(HuntGameWS.class.getName()).log(Level.SEVERE, null, ex);
}
return true;
}
/**
* Web service operation
*/
@WebMethod(operationName = "createMProfile")
public boolean createMProfile(@WebParam(name = "objMProfile")
MProfile objMProfile) {
try {
if (m_dbHandler == null) {
m_dbHandler = new DatabaseHandler();
}
return m_dbHandler.createMProfile(objMProfile);
} catch (ClassNotFoundException ex) {
Logger.getLogger(HuntGameWS.class.getName()).log(Level.SEVERE, null, ex);
return false;
} catch (SQLException ex) {
Logger.getLogger(HuntGameWS.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
}
}
As you see one Method is using a class as a parameter. this class looks that way:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "mProfile", propOrder = {
"email",
"firstName",
"gender",
"lastName",
"pwd",
"userName"
})
public class MProfile {
protected String email;
protected String firstName;
protected String gender;
protected String lastName;
protected String pwd;
protected String userName;
/**
* Gets the value of the email property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getEmail() {
return email;
}
/**
* Sets the value of the email property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setEmail(String value) {
this.email = value;
}
/**
* Gets the value of the firstName property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getFirstName() {
return firstName;
}
/**
* Sets the value of the firstName property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setFirstName(String value) {
this.firstName = value;
}
/**
* Gets the value of the gender property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getGender() {
return gender;
}
/**
* Sets the value of the gender property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setGender(String value) {
this.gender = value;
}
/**
* Gets the value of the lastName property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getLastName() {
return lastName;
}
/**
* Sets the value of the lastName property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setLastName(String value) {
this.lastName = value;
}
/**
* Gets the value of the pwd property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPwd() {
return pwd;
}
/**
* Sets the value of the pwd property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPwd(String value) {
this.pwd = value;
}
/**
* Gets the value of the userName property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getUserName() {
return userName;
}
/**
* Sets the value of the userName property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setUserName(String value) {
this.userName = value;
}
}
The client application which uses the WebService is an android-Programm which are using the KSOAP2-Framework to make calls. The method calls to the methods with the primitiv datatypes are working fine. But the method call to the method with the class as parameter is making a problem. When I'm debuging the serverside the parameter is always null. I've logged the soapcall which is looking that way:
POST /HuntGameWebService/HuntGameWSService HTTP/1.1
User-Agent: kSOAP/2.0
SOAPAction: createMProfile
Content-Type: text/xml
Connection: close
Content-Length: 805
Host: xxxxxxxxxxxx
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<n0:createMProfile id="o0" c:root="1" xmlns:n0="http://WebService.HuntGame.markus_heid.com/">
<createMProfile i:type="n0:createMProfile">
<objMProfile i:type="d:anyType">
<username i:type="d:string">user</username>
<firstname i:type="d:string">user</firstname>
<lastname i:type="d:string">user</lastname>
<birthdate i:type="d:long">57751920000000</birthdate>
<gender i:type="d:string">w</gender>
<email i:type="d:string">user@user.com</email>
<pwd i:type="d:string">5cc32e366c87c4cb49e4309b75f57d64</pwd>
</objMProfile>
</createMProfile>
</n0:createMProfile>
</v:Body>
</v:Envelope>
I've trying a few things right now to find out what's wrong but I didn't had any success. So does anyone here knows what's wrong?
Thanks
Markus