Hi,
ich versuche gerade einen Webservice zu programmieren. Da ich neu in diesen Gebiet bin, bin ich ganz naiv vorgegangen und habe mit Netbeans einen Webservice ersellt. Der sieht so aus:
Wie man sieht hat eine der Methoden eine Klasse als Parameter. Die Klasse sieht so aus:
Der Client, der den WebService aufruft befindet sich auf der android-plattform. Als framework benutze ich dort KSOAP2. Der Aufruf der einfachen Methoden läuft auch gut. Jedoch gibt es Probleme beim Aufruf der Methode mit der Klasse als Parameter. Hier bekomme ich auf den Server im die Objektreferenz null, obwohl eine SOAP-Message an den Server geschickt worden ist. Die Message sieht so aus:
Leider habe ich keine Ahnung, was hier falsch läuft. Hat irgendjemand eine Idee?
Danke im vorraus
Markus
ich versuche gerade einen Webservice zu programmieren. Da ich neu in diesen Gebiet bin, bin ich ganz naiv vorgegangen und habe mit Netbeans einen Webservice ersellt. Der sieht so aus:
Code:
@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;
}
}
}
Code:
@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;
}
}
Code:
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>
Leider habe ich keine Ahnung, was hier falsch läuft. Hat irgendjemand eine Idee?
Danke im vorraus
Markus