apache2 + php5 + mysql5
tomcat5.5 + j2sdk 1.4.2 + mysql5
表结构
CODE:[Copy to clipboard]CREATE TABLE `test` (
`id` int(11) NOT NULL auto_increment,
`val` varchar(22) collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=10 ;
wsdl为
CODE:[Copy to clipboard]<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="
http://192.168.1.52:8080/axis/HelloClient.jws" xmlns:apachesoap="
http://xml.apache.org/xml-soap" xmlns:impl="
http://192.168.1.52:8080/axis/HelloClient.jws" xmlns:intf="
http://192.168.1.52:8080/axis/HelloClient.jws" xmlns:soapenc="
http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="
http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="
http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="
http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.3
Built on Oct 05, 2005 (05:23:37 EDT)-->
<wsdl:types>
<schema targetNamespace="
http://192.168.1.52:8080/axis/HelloClient.jws" xmlns="
http://www.w3.org/2001/XMLSchema">
<import namespace="
http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="ArrayOf_xsd_anyType">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:anyType[]"/>
</restriction>
</complexContent>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="getNameResponse">
<wsdl:part name="getNameReturn" type="impl:ArrayOf_xsd_anyType"/>
</wsdl:message>
<wsdl:message name="getNameRequest">
<wsdl:part name="name" type="xsd:string"/>
</wsdl:message>
<wsdl:portType name="HelloClient">
<wsdl:operation name="getName" parameterOrder="name">
<wsdl:input message="impl:getNameRequest" name="getNameRequest"/>
<wsdl:output message="impl:getNameResponse" name="getNameResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloClientSoapBinding" type="impl:HelloClient">
<wsdlsoap:binding style="rpc" transport="
http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getName">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getNameRequest">
<wsdlsoap:body encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/" namespace="
http://DefaultNamespace" use="encoded"/>
</wsdl:input>
<wsdl:output name="getNameResponse">
<wsdlsoap:body encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/" namespace="
http://192.168.1.52:8080/axis/HelloClient.jws" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloClientService">
<wsdl:port binding="impl:HelloClientSoapBinding" name="HelloClient">
<wsdlsoap:address location="
http://192.168.1.52:8080/axis/HelloClient.jws"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
实现这个wsdl的程序为
CODE:[Copy to clipboard]import java.sql.*;
import java.util.ArrayList;
public class HelloClient{
public ArrayList getName(String name){
String name2;
//name2 = new String(name.getBytes("GB2312"));
name2 = name;
try{
Connection conn;
Statement stmt;
ResultSet res;
Class.forName("com.mysql.jdbc.Driver").newInstance();
//Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://192.168.1.46:3000/disk", "remote", "123123");
stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO test SET `val` = '" + name2 + "'");
stmt.close();
conn.close();
}catch (Exception ex){
System.out.println("Error : " + ex.toString());
}
ArrayList arr = new ArrayList(3);
arr.add("123");
arr.add("345");
arr.add("INSERT INTO test SET `val` = '" + name2 + "'");
return arr;
}
}
我用php + nusoap 往这个里面写数据, 中文处理正常(但在页面显示时是乱码, 数据最后进数据库了)
CODE:[Copy to clipboard]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?
class Debug{
function startTimer(){
global $starttime;
$mtime = microtime ();
$mtime = explode (' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
}
function endTimer(){
global $starttime;
$mtime = microtime ();
$mtime = explode (' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = round (($endtime - $starttime), 5);
return $totaltime;
}
}
$debug = new Debug();
$debug->startTimer();
require_once ('./lib/nusoap/lib/nusoap.php');
$s=new soapclient('
http://192.168.1.52:8080/axis/HelloClient.jws?wsdl', 'wsdl');
$s->soap_defencoding = 'UTF-8';
$s->decode_utf8 = false;
$p=$s->getProxy();
//include("./class.Chinese.php");
//$chs = new Chinese("GB2312","UTF8",$_POST['aa']);
//$a = $chs->ConvertIT();
$arr=$p->getName($_POST['aa']);
echo "<pre>";
print_r($arr);
$runtime = $debug->endTimer();
echo $runtime;
?>
</body>
</html>
然后
第二个wsdl
主要是从数据库中读数据
CODE:[Copy to clipboard]<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="
http://192.168.1.52:8080/axis/MysqlTest.jws" xmlns:apachesoap="
http://xml.apache.org/xml-soap" xmlns:impl="
http://192.168.1.52:8080/axis/MysqlTest.jws" xmlns:intf="
http://192.168.1.52:8080/axis/MysqlTest.jws" xmlns:soapenc="
http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="
http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="
http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="
http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.3
Built on Oct 05, 2005 (05:23:37 EDT)-->
<wsdl:types>
<schema targetNamespace="
http://192.168.1.52:8080/axis/MysqlTest.jws" xmlns="
http://www.w3.org/2001/XMLSchema">
<import namespace="
http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="ArrayOf_xsd_anyType">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:anyType[]"/>
</restriction>
</complexContent>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="testRequest">
</wsdl:message>
<wsdl:message name="testResponse">
<wsdl:part name="testReturn" type="impl:ArrayOf_xsd_anyType"/>
</wsdl:message>
<wsdl:portType name="MysqlTest">
<wsdl:operation name="test">
<wsdl:input message="impl:testRequest" name="testRequest"/>
<wsdl:output message="impl:testResponse" name="testResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MysqlTestSoapBinding" type="impl:MysqlTest">
<wsdlsoap:binding style="rpc" transport="
http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="test">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="testRequest">
<wsdlsoap:body encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/" namespace="
http://DefaultNamespace" use="encoded"/>
</wsdl:input>
<wsdl:output name="testResponse">
<wsdlsoap:body encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/" namespace="
http://192.168.1.52:8080/axis/MysqlTest.jws" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MysqlTestService">
<wsdl:port binding="impl:MysqlTestSoapBinding" name="MysqlTest">
<wsdlsoap:address location="
http://192.168.1.52:8080/axis/MysqlTest.jws"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
实现这个wsdl的java程序为
CODE:[Copy to clipboard]import java.sql.*;
import java.util.ArrayList;
public class MysqlTest{
public ArrayList test(){
ArrayList arr = new ArrayList(2);
try{
Connection conn;
Statement stmt;
ResultSet res;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://192.168.1.46:3000/disk", "remote", "123123");
stmt = conn.createStatement();
res = stmt.executeQuery("select * from test");
int i = 0;
while (res.next()){
arr.add(res.getString("val"));
i++;
}
res.close();
stmt.close();
conn.close();
arr.add(Integer.toString(i));
return arr;
}catch (Exception ex){
arr.add("Error: " + ex.toString());
return arr;
}
}
}
php的是
CODE:[Copy to clipboard]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?
class Debug{
function startTimer(){
global $starttime;
$mtime = microtime ();
$mtime = explode (' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
}
function endTimer(){
global $starttime;
$mtime = microtime ();
$mtime = explode (' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = round (($endtime - $starttime), 5);
return $totaltime;
}
}
$debug = new Debug();
$debug->startTimer();
require_once ('./lib/nusoap/lib/nusoap.php');
$s=new soapclient('
http://192.168.1.52:8080/axis/MysqlTest.jws?wsdl', 'wsdl');
echo $s->soap_defencoding;
//$s->soap_defencoding = 'UTF-8';
$s->decode_utf8 = true;
$p=$s->getProxy();
$arr=$p->test();
include("./class.Chinese.php");
$chs = new Chinese("UTF8","GB2312",$arr[0]);
echo $chs->ConvertIT();
echo iconv("GB2312", "UTF-8", $arr[1]);
echo iconv("ISO-8859-1", "UTF-8", $arr[2]);
echo iconv("UTF-8", "GB2312", $arr[3]);
//UNICODE UTF8 GB2312
echo "<pre>";
print_r($arr);
$runtime = $debug->endTimer();
echo $runtime;
?>
</body>
</html>