configureWSDL(“utknewswsdl”,”urn:utknewswsdl”);
$server->wsdl->addComplexType(
“groups”, “complextype”,
“struct”,
“all”,
“”,
array(“Id”=>array(“name”=>”Id”,”type”=>”xsd:interger”),
“userName”=>array(“name”=>”userName”,”type”=>”xsd:string”),
“administrator”=>array(“name”=>”administrator”,”type”=>”xsd:string”),
“announcer”=>array(“name”=>”announcer”,”type”=>”xsd:string”),
“audience”=>array(“name”=>”audience”,”type”=>”xsd:string”),));
$server->wsdl->addComplexType(
‘gdarray’,
‘complexType’,
‘array’,
‘all’,
‘SOAP-ENC:Array’,
array(),
array(array(‘ref’=>’SOAP-ENC:arrayType’,’wsdl:arrayType’=>’tns:groups[]’)),
‘tns:groups’);
$server->register(“authenUser”,
array(“username”=>”xsd:string”,”password”=>”xsd:string”,),
array(“return”=>”tns:groups”),
“urn:utknewswsdl”,
“urn:utknewswsdl/authenUser”,
“rpc”,
“encoded”,
“return data of product”);
function authenUser($username,$password)
{
$sql = “select Id,userName,administrator,announcer,audience from user “;
$sql .= “where userId ='”. $username.”‘ and password ='”.$password.”‘” ;
$sql .= “and userStatus ‘Delete’ ;”;
$rs = mysql_query($sql);
$rowNo = mysql_num_rows($rs);
if($rowNo == 0){
$rsAuthen = array();
}
else{
$rsAuthen = array();
$i=0;
while($data = mysql_fetch_array($rs)){
$rsAuthen[“Id”] = $data[0];
$rsAuthen[“userName”] = $data[1];
$rsAuthen[“administrator”] = $data[2];
$rsAuthen[“announcer”] = $data[3];
$rsAuthen[“audience”] = $data[4];
$i++;
}
}
return $rsAuthen;
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA: “”;
$server->service($HTTP_RAW_POST_DATA);
?>
ส่วนของแอนดรอยด์
package com.sun.android.project1;
import java.util.Vector;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Project1Activity extends Activity {
private static final String SOAP_ACTION = "urn:utknewswsdl/authenUser";
private static final String METHOD_NAME = "authenUser";
private static final String NAMESPACE = "urn:utknewswsdl";
private static final String URL = "http://192.168.1.33/AndroidProject/testchkuser1.php";
private TextView tv;
private EditText userText;
private EditText passwordText;
private Object resultsRequestSOAP = null ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.textDataUser);
Button startButton = (Button) findViewById(R.id.loginButton);
userText = (EditText) findViewById(R.id.userText) ;
passwordText = (EditText) findViewById(R.id.passwordText) ;
tv.setText("Result:");
startButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("arg1",userText.getText().toString());
request.addProperty("arg2", passwordText.getText().toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = request;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
resultsRequestSOAP = envelope.getResponse();
String[] results = (String[]) resultsRequestSOAP;//ส่วนที่ใช้รับค่า
tv.setText( results[0]);
} catch (Exception aE) {
aE.printStackTrace();
}
}
});
}
}
*รันแล้วไม่แสดงผลอะไรเลยค่ะ รบกวนผู้รู้ช่วยดูให้ทีนะคะ ติดตรงนี้มานานมากแล้ว ยังทำไม่ได้เลยคะ
อะไร ? จะทำไรครับ? ไม่ค่อยเข้าใจ แต่ลองใช้
for วน add array ค่าที่รับมาให้อยู่ในตัวแปรหนึ่งก็ได้นิครับ??
แต่ผมว่ากว่ามันจะประมวลผลแต่ละforเสร็จมันก็ค่อนข้างเสีย เวลา เสียไปเป็นวิๆๆโดยเปล่าประโยชน์เลยทีเดียว ฉะนั้น ส่งไปแยกๆๆไม่ต้องรวมarrayดีแล้วครับ