大家知道,用dataset传递的webservice,微软会在各个节点加上schema,所以无法与j2ee,flash兼容,所以我找到了一种转换他们变成普通xml的方法。代码如下:
方法一:
public class datasettoxml : inherits system.web.ui.page
private sub page_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
dim objconn as sqlconnection
dim strsql as string
strsql = "select top 10 * from customers"
objconn = new sqlconnection(configurationsettings.appsettings("connectionstring"))
dim sdacust as new sqldataadapter(strsql, objconn)
dim dstcust as new dataset()
sdacust.fill(dstcust, "customers")
'save data to xml file and schema file
dstcust.writexml(server.mappath("customers.xml"),xmlwritemode.ignoreschema)
dstcust.writexmlschema(server.mappath("customers.xsd"))
end sub
这种方法是写入一个xml文件
方法二:
<webmethod(description:="所有教室列表")> _
public function listallrooms() as xmldocument
try
m_cpcoursearrange.fillroomid(m_dscoursearrange)
'dim reader as new memorystream
dim doc as new xmldocument
doc.loadxml(m_dscoursearrange.getxml.tostring)
return doc
catch ex as protocols.soapexception
throw soapexceptione.raiseexception("listallrooms", "http://tempuri.org/coursearrange", ex.message, "4000", ex.source, soapexceptione.faultcode.server)
end try
end function
getxml--returns the xml representation of the data stored in the dataset. (msdn)
private shared sub demonstrategetxml()
' create a dataset with one table containing two columns and 10 rows.
dim ds as dataset = new dataset("mydataset")
dim t as datatable = ds.tables.add("items")
t.columns.add("id", type.gettype("system.int32"))
t.columns.add("item", type.gettype("system.string"))
' add ten rows.
dim r as datarow
dim i as integer
for i = 0 to 9
r = t.newrow()
r("id") = i
r("item")= "item" & i
t.rows.add(r)
next
' display the dataset contents as xml.
console.writeline( ds.getxml() )
end sub
看来以后用dataset传递的时候也不用为它的转换发愁了。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器