您的程序是否也需要自动更新,您是否已有类似的尝试,这里发布一下我的做法,请各位参考,不当之处还请指正。
文章现在写得有点粗,相关源文件我在稍候补上。
1,准备工作
1)安装应用服务器TOMCAT6+JDK1.5
这里采用Xfire1.2开发WEB服务,程序中使用了LIST的范型,所以采用了JDK1.5,安装方法如下:
安装JDK1.5,然后在环境变量中配置JAVA_HOME=C:/Program Files/Java/jdk1.5.0_03(具体位置请参看自已的安装目录)
下载tomcat6,运行其bin子目录下的startup.bat即可运行TOMCAT6
2)创建表
/*==============================================================*/
/* Table: EIS_update */
/*==============================================================*/
create table EIS_update (
toid VARCHAR2(18) not null,
tcurrentVersion VARCHAR2(18),
tnextVersion VARCHAR2(18),
tpackage VARCHAR2(100),
tinstallpath VARCHAR2(100),
constraint PK_EIS_UPDATE primary key (toid)
);
toid:关键字
tcurrentVersion:当前程序版本
tnextVersion:下一程序版本
tpackage:安装包路径,支持绝对路径(/update/1.zip)和相对路径(http://localhost:8080/mis/update/1.zip)
tinstallpath :程序的安装路径,默认为当前目录(更新程序所在目录),可采用相对路径和绝对路径
2,部署WEB服务
1)这里需要hibernate3.1的支持,先建立好 表EIS_update对应的DAO,检查程序如下:
import
java.util.List;
import
org.hibernate.Session;
import
org.hibernate.Transaction;
import
com.ktsoft.webservices.userservice.dao.
*
;
/** */
/**
* 版本检查服务
*/

public
class
CheckVersionImpl
implements
ICheckVersion
...
{
EisUpdate update;
public String Welcome() ...{
return "欢迎使用EISAnywhere自动更新服务";
}

/** *//**
* 返回应用程序解压缩路径
* 可以使用绝对路径或相对路径
*/
public String getInstallPath() ...{
if(update==null)return null;
else return update.getTinstallpath();
}

/** *//**
* 返回程序安装包路径,目前只支持zip包
* 该路径为相对路径,如/update/123.zip
* 绝对返回路径需要客户端提供服务器URL
*/
public String getUpdateFileURL() ...{
if(update==null)return null;
else return update.getTpackage();
}

/** *//**
* 获得该软件的下一版本信息,如果该软件未注册下一版本信息,则说明该软件不需要更新
*/
public String getVersion(String version) ...{
// TODO Auto-generated method stub
EisUpdateDAO updatedao=new EisUpdateDAO();
Session session=updatedao.getSession();
Transaction trans=session.beginTransaction();
List <EisUpdate> list=updatedao.findByTcurrentversion(version);
for(EisUpdate o:list)...{
update=o;
}
session.close();
if(update==null)...{
return version;
}else ...{
return update.getTnextversion();
}
}
}
由于WAR包有5M左右,不是很好发,有需要的博友可以与我联系。
如果配置正常的情况下,我们可以检查一下WEB服务:启动TOMCAT服务器,在浏览中录入http://localhost:8080/EISAnywhereUpdate/services/CheckVersion?wsdl,会得到以下结果:
<?
xml version="1.0" encoding="UTF-8"
?>
-
<
wsdl:definitions
targetNamespace
="http://eisanywhereupdate.ktsoft.com"
xmlns:tns
="http://eisanywhereupdate.ktsoft.com"
xmlns:wsdlsoap
="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12
="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsd
="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc11
="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenc12
="http://www.w3.org/2003/05/soap-encoding"
xmlns:soap11
="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsdl
="http://schemas.xmlsoap.org/wsdl/"
>
-
<
wsdl:types
>
-
<
xsd:schema
xmlns:xsd
="http://www.w3.org/2001/XMLSchema"
attributeFormDefault
="qualified"
elementFormDefault
="qualified"
targetNamespace
="http://eisanywhereupdate.ktsoft.com"
>
-
<
xsd:element
name
="getUpdateFileURL"
>
<
xsd:complexType
/>
</
xsd:element
>
-
<
xsd:element
name
="getUpdateFileURLResponse"
>
-
<
xsd:complexType
>
-
<
xsd:sequence
>
<
xsd:element
maxOccurs
="1"
minOccurs
="1"
name
="out"
nillable
="true"
type
="xsd:string"
/>
</
xsd:sequence
>
</
xsd:complexType
>
</
xsd:element
>
-
<
xsd:element
name
="getVersion"
>
-
<
xsd:complexType
>
-
<
xsd:sequence
>
<
xsd:element
maxOccurs
="1"
minOccurs
="1"
name
="in0"
nillable
="true"
type
="xsd:string"
/>
</
xsd:sequence
>
</
xsd:complexType
>
</
xsd:element
>
-
<
xsd:element
name
="getVersionResponse"
>
-
<
xsd:complexType
>
-
<
xsd:sequence
>
<
xsd:element
maxOccurs
="1"
minOccurs
="1"
name
="out"
nillable
="true"
type
="xsd:string"
/>
</
xsd:sequence
>
</
xsd:complexType
>
</
xsd:element
>
-
<
xsd:element
name
="Welcome"
>
<
xsd:complexType
/>
</
xsd:element
>
-
<
xsd:element
name
="WelcomeResponse"
>
-
<
xsd:complexType
>
-
<
xsd:sequence
>
<
xsd:element
maxOccurs
="1"
minOccurs
="1"
name
="out"
nillable
="true"
type
="xsd:string"
/>
</
xsd:sequence
>
</
xsd:complexType
>
</
xsd:element
>
-
<
xsd:element
name
="getInstallPath"
>
<
xsd:complexType
/>
</
xsd:element
>
-
<
xsd:element
name
="getInstallPathResponse"
>
-
<
xsd:complexType
>
-
<
xsd:sequence
>
<
xsd:element
maxOccurs
="1"
minOccurs
="1"
name
="out"
nillable
="true"
type
="xsd:string"
/>
</
xsd:sequence
>
</
xsd:complexType
>
</
xsd:element
>
</
xsd:schema
>
</
wsdl:types
>
-
<
wsdl:message
name
="getInstallPathResponse"
>
<
wsdl:part
name
="parameters"
element
="tns:getInstallPathResponse"
/>
</
wsdl:message
>
-
<
wsdl:message
name
="WelcomeResponse"
>
<
wsdl:part
name
="parameters"
element
="tns:WelcomeResponse"
/>
</
wsdl:message
>
-
<
wsdl:message
name
="getVersionResponse"
>
<
wsdl:part
name
="parameters"
element
="tns:getVersionResponse"
/>
</
wsdl:message
>
-
<
wsdl:message
name
="WelcomeRequest"
>
<
wsdl:part
name
="parameters"
element
="tns:Welcome"
/>
</
wsdl:message
>
-
<
wsdl:message
name
="getVersionRequest"
>
<
wsdl:part
name
="parameters"
element
="tns:getVersion"
/>
</
wsdl:message
>
-
<
wsdl:message
name
="getInstallPathRequest"
>
<
wsdl:part
name
="parameters"
element
="tns:getInstallPath"
/>
</
wsdl:message
>
-
<
wsdl:message
name
="getUpdateFileURLRequest"
>
<
wsdl:part
name
="parameters"
element
="tns:getUpdateFileURL"
/>
</
wsdl:message
>
-
<
wsdl:message
name
="getUpdateFileURLResponse"
>
<
wsdl:part
name
="parameters"
element
="tns:getUpdateFileURLResponse"
/>
</
wsdl:message
>
-
<
wsdl:portType
name
="CheckVersionPortType"
>
-
<
wsdl:operation
name
="getUpdateFileURL"
>
<
wsdl:input
name
="getUpdateFileURLRequest"
message
="tns:getUpdateFileURLRequest"
/>
<
wsdl:output
name
="getUpdateFileURLResponse"
message
="tns:getUpdateFileURLResponse"
/>
</
wsdl:operation
>
-
<
wsdl:operation
name
="getVersion"
>
<
wsdl:input
name
="getVersionRequest"
message
="tns:getVersionRequest"
/>
<
wsdl:output
name
="getVersionResponse"
message
="tns:getVersionResponse"
/>
</
wsdl:operation
>
-
<
wsdl:operation
name
="Welcome"
>
<
wsdl:input
name
="WelcomeRequest"
message
="tns:WelcomeRequest"
/>
<
wsdl:output
name
="WelcomeResponse"
message
="tns:WelcomeResponse"
/>
</
wsdl:operation
>
-
<
wsdl:operation
name
="getInstallPath"
>
<
wsdl:input
name
="getInstallPathRequest"
message
="tns:getInstallPathRequest"
/>
<
wsdl:output
name
="getInstallPathResponse"
message
="tns:getInstallPathResponse"
/>
</
wsdl:operation
>
</
wsdl:portType
>
-
<
wsdl:binding
name
="CheckVersionHttpBinding"
type
="tns:CheckVersionPortType"
>
<
wsdlsoap:binding
style
="document"
transport
="http://schemas.xmlsoap.org/soap/http"
/>
-
<
wsdl:operation
name
="getUpdateFileURL"
>
<
wsdlsoap:operation
soapAction
=""
/>
-
<
wsdl:input
name
="getUpdateFileURLRequest"
>
<
wsdlsoap:body
use
="literal"
/>
</
wsdl:input
>
-
<
wsdl:output
name
="getUpdateFileURLResponse"
>
<
wsdlsoap:body
use
="literal"
/>
</
wsdl:output
>
</
wsdl:operation
>
-
<
wsdl:operation
name
="getVersion"
>
<
wsdlsoap:operation
soapAction
=""
/>
-
<
wsdl:input
name
="getVersionRequest"
>
<
wsdlsoap:body
use
="literal"
/>
</
wsdl:input
>
-
<
wsdl:output
name
="getVersionResponse"
>
<
wsdlsoap:body
use
="literal"
/>
</
wsdl:output
>
</
wsdl:operation
>
-
<
wsdl:operation
name
="Welcome"
>
<
wsdlsoap:operation
soapAction
=""
/>
-
<
wsdl:input
name
="WelcomeRequest"
>
<
wsdlsoap:body
use
="literal"
/>
</
wsdl:input
>
-
<
wsdl:output
name
="WelcomeResponse"
>
<
wsdlsoap:body
use
="literal"
/>
</
wsdl:output
>
</
wsdl:operation
>
-
<
wsdl:operation
name
="getInstallPath"
>
<
wsdlsoap:operation
soapAction
=""
/>
-
<
wsdl:input
name
="getInstallPathRequest"
>
<
wsdlsoap:body
use
="literal"
/>
</
wsdl:input
>
-
<
wsdl:output
name
="getInstallPathResponse"
>
<
wsdlsoap:body
use
="literal"
/>
</
wsdl:output
>
</
wsdl:operation
>
</
wsdl:binding
>
-
<
wsdl:service
name
="CheckVersion"
>
-
<
wsdl:port
name
="CheckVersionHttpPort"
binding
="tns:CheckVersionHttpBinding"
>
<
wsdlsoap:address
location
="http://localhost:8080/EISAnywhereUpdate/services/CheckVersion"
/>
</
wsdl:port
>
</
wsdl:service
>
</
wsdl:definitions
>
3,部署客户端
4,在程序中实现版本检测
在.net程序中引用WEB服务,读取本地版本,通过WEB服务检验下一版本,如果版本与本地版本则不需要更新,否则启用更新程序。
//
连接到WebServices,检查版本信息
EISAnywhereUpdate.CheckVersion checkVersion
=
new
EISAnywhereUpdate.CheckVersion(config.getUpdateUrl()
+
"
/services/CheckVersion
"
);
remote_version
=
checkVersion.getVersion(local_version);
if
(local_version
==
remote_version)
...
{
//打开主程序窗口
MainFrame frame = new MainFrame(config,employee);
frame.Show();
this.Hide();
}

else
...
{
MessageBox.Show("系统检验到新的补丁,请先更新程序", "EISAnywhere-Ktsoft");
Process p = new Process();
p.StartInfo.FileName = @"" + Application.StartupPath + "/" + "EISAnywhereUpdate.exe";
p.Start();
Environment.Exit(0);
return;
}
794

被折叠的 条评论
为什么被折叠?



