我正在使用PHP和NuSOAP创建一个简单的Web服务,它从数据库中返回一些数据。我已经制作了一个Android应用程序来使用ksoap2来使用该服务。在localhost中一切正常,但是当我在实时服务器上传输服务(需要修改)时,我会收到肥皂故障响应以及http 500错误。这是Android应用中的响应转储。
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><SOAP-ENV:Fault><faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode><faultactor xsi:type="xsd:string"></faultactor><faultstring xsi:type="xsd:string">error in msg parsing:
XML error parsing SOAP payload on line 1: Not well-formed (invalid token)</faultstring><detail xsi:type="xsd:string"></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
我对此错误感到困惑,我无法找到原因,因为在localhost或实时服务器上测试时发送的请求完全相同,但在第二种情况下它不起作用。这是请求转储:
<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:listAllActions id="o0" c:root="1" xmlns:n0="http://www.somi92.student.elab.fon.bg.ac.rs/soap/ActionList/" />
</v:Body></v:Envelope>
这是我在PHP中的服务:
<?php
$server = new soap_server();
$namespace = "http://somi92.student.elab.fon.bg.ac.rs/HSMSWebService/index.php";
$server -> configureWSDL("ActionList");
$server -> wsdl -> schemaTargetNamespace = $namespace;
$server -> register("listAllActions",
array(),
array("return" => "xsd:string"),
"urn:ActionList",
"urn:ActionList#listAllActions",
"rpc",
"literal",
"Get a listing of actions");
$server->service('php://input');
function listAllActions() {
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASS);
if(!$conn)
{
die("Could not connect: " . mysql_error());
}
// echo "Connected successfully!\n";
$hsms = array(
"desc" => "",
"num" => "",
"price" => "",
"org" => "",
"web" => "");
$actions = array();
$sql_query = "select HB.hb_id, HB.opis, HB.broj, HB.cena, ORG.naziv, ORG.website ".
"from HUMANITARNI_BROJ HB join ORGANIZACIJA ORG on (HB.org_id = ORG.org_id); ";
"order by HB.prioritet;";
mysql_select_db(DB_NAME);
mysql_query ("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'");
$result = mysql_query($sql_query, $conn);
if(!$result)
{
die("Could not execute query: ".mysql_error());
}
while($table_row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$hsms = array(
"desc" => $table_row["opis"],
"num" => $table_row["broj"],
"price" => $table_row["cena"],
"org" => $table_row["naziv"],
"web" => $table_row["website"]);
$actions["action"][] = $hsms;
}
mysql_free_result($result);
mysql_close($conn);
return json_encode($actions);
}
?>
这是Android中的服务消费者
private static String SOAP_ACTION = "http://www.somi92.student.elab.fon.bg.ac.rs/soap/ActionList/listAllActions";
private static String NAMESPACE = "http://www.somi92.student.elab.fon.bg.ac.rs/soap/ActionList/";
private static String METHOD_NAME = "listAllActions";
private static String URL = "http://www.somi92.student.elab.fon.bg.ac.rs/HSMSWebService/index.php";
.....
SoapObject soapRequest = new SoapObject(NAMESPACE,METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes = true;
envelope.setOutputSoapObject(soapRequest);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
parent.receiveData(e.getMessage()+" IO");
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("XML greska", e.getMessage());
parent.receiveData(e.getMessage()+" XML");
} catch (Exception e) {
// TODO: handle exception
parent.receiveData(e.getMessage()+" EXC");
}
try {
// SoapObject result = (SoapObject)envelope.bodyIn;
SoapObject result = null;
String message = "";
if(envelope.bodyIn instanceof SoapFault) {
message = ((SoapFault)envelope.bodyIn).faultstring;
} else {
result = (SoapObject)envelope.bodyIn;
}
if(result != null) {
JSONObject obj = new JSONObject(result.getProperty(0).toString());
parent.receiveData(obj.toString());
} else {
parent.receiveData("SOAP respones: "+"NULL!"+" "+message);
}
Log.e("dump Request: " ,androidHttpTransport.requestDump.toString());
Log.e("dump response: " ,androidHttpTransport.responseDump.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
parent.receiveData(e.getMessage()+" Error");
}
}
我现在已经挣扎了好几天了,我找不到解决办法。任何帮助表示赞赏。感谢。