Web服务中的xml数据连接 [英] xml data connection in Web Services

查看:72
本文介绍了Web服务中的xml数据连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个Web服务来为产品公开一个XML文件,以便客户端应用程序使用并填充一个

数据网格。结束。


我已经用简单的数学成功测试了网络服务

返回如下:

<%@ WebService Language = " VB"类= QUOT; aWebService" %>

Imports System.Web

Imports System.Web.Services

Imports System.Web.Services.Protocols

< WebService(Namespace:=" http://tempuri.org/")_

< WebServiceBinding(ConformsTo:= WsiProfiles.BasicPr ofile1_1)_

公共类aWeb服务

继承System.Web.Services.WebService

< System.Web.Services.WebMethod()_

公共功能SquareRootTimesSide(ByVal对角线为双倍)_

双倍

返回(对角线* System.Math.Sqrt(2))

结束功能

结束班级

所以我想我会尝试公开结构化数据。我主要使用XML文件

作为我的数据源,所以我想坚持下去。

我已成功实现将XML文件读入

本地.aspx页面,包含以下代码:

< script runat =" server">

私有函数MakeDataView()as DataView

Dim myDataSet As New DataSet()

myDataSet.ReadXml(Server.MapPath(" Manufacturers.xm l"))

Dim view As DataView = New DataView (myDataSet.Tables(0))

view.AllowDelete = False

view.AllowEdit = False

view.AllowNew = False

view.Sort =" name ASC"

返回视图

结束函数

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Dim view as DataView = MakeDataView()

dgManufacturers.DataSource = view

dgManufacturers.AllowSorting = True

dgManufacturers.DataBind()

结束子

< / script>

如何将服务器端代码编写为Web方法?

非常感谢!!

Brock

I''m trying to develop a web service to expose an XML file for product
manufacturers for a client application to consume and populate a
datagrid on the consuming end.

I have successfully tested the web service with simple mathematic
returns like:
<%@ WebService Language="VB" Class="aWebService" %>
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace := "http://tempuri.org/")_
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicPr ofile1_1)_
Public Class aWebService
Inherits System.Web.Services.WebService
<System.Web.Services.WebMethod()_
Public Function SquareRootTimesSide(ByVal Diagonal As Double) _
As Double
Return (Diagonal * System.Math.Sqrt(2))
End Function
End Class
So I thought I''d try exposing structured data. I use mostly XML files
for my datasources so I''d like to stick with that.
I have successfully implemented reading the XML file into a
local .aspx page with this code:
<script runat="server">
Private Function MakeDataView() as DataView
Dim myDataSet As New DataSet()
myDataSet.ReadXml(Server.MapPath("Manufacturers.xm l"))
Dim view As DataView = New DataView(myDataSet.Tables(0))
view.AllowDelete = False
view.AllowEdit = False
view.AllowNew = False
view.Sort = "name ASC"
Return view
End Function
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim view as DataView = MakeDataView()
dgManufacturers.DataSource = view
dgManufacturers.AllowSorting = True
dgManufacturers.DataBind()
End Sub
</script>
How can I write the server-side code as a web method?
Many thanks!!
Brock

推荐答案

" Brock" < wa ******** @ yahoo.comwrote in message

news:0b ********************** ************ @ r38g2000 prr.googlegroups.com ...
"Brock" <wa********@yahoo.comwrote in message
news:0b**********************************@r38g2000 prr.googlegroups.com...

>

怎么能我把服务器端代码写成web方法?
>
How can I write the server-side code as a web method?



你不是。您的Web服务代码将关注Web服务。

不是DataView或DataSet。


将您的webmethod编码为函数返回类型System.Xml.XmlDocument 。

然后做这样的事情:


Dim doc As New XmlDocument

doc.Load(Server.MapPath(" Manufacturers.xml))

返回doc


-

John Saunders | MVP - 连接系统开发人员

You don''t. Your web service code will be concerned with web service things.
Not DataView or DataSet.

Code your webmethod as a function returning type System.Xml.XmlDocument.
Then do something like this:

Dim doc As New XmlDocument
doc.Load(Server.MapPath("Manufacturers.xml"))
Return doc

--
John Saunders | MVP - Connected System Developer


在您的行中:Dim doc As New XmlDocument" " XmlDocument的"是不是

被接受...应该是XmlDataSource?


In" doc.Load(Server.MapPath(" Manufacturers。) xml"))''我得到'''公开

事件加载(sender As Object,e As System.EventArgs)''是一个事件,而

不能直接打电话。使用''RaiseEvent''语句来举起一个

的事件。


我试了这个但没有运气:


< System.Web.Services.WebMethod()_

私人函数GetManufacturers(ByVal sender As Object,ByVal e

As System.EventArgs)处理GetManufacturers

Dim doc As New XmlDataSource

doc.Load(Server.MapPath(" Manufacturers.xml))

返回doc

结束功能

In your line: "Dim doc As New XmlDocument" "XmlDocument" is not
being accepted... should this be "XmlDataSource"?

In "doc.Load(Server.MapPath("Manufacturers.xml")) '' I get "''Public
Event Load(sender As Object, e As System.EventArgs)'' is an event, and
cannot be called directly. Use a ''RaiseEvent'' statement to raise an
event."

I tried this with no luck:

<System.Web.Services.WebMethod()_
Private Function GetManufacturers(ByVal sender As Object, ByVal e
As System.EventArgs) Handles GetManufacturers
Dim doc As New XmlDataSource
doc.Load(Server.MapPath("Manufacturers.xml"))
Return doc
End Function


>

将您的webmethod编码为函数返回类型System.Xml.XmlDocument 。

然后做这样的事情:


Dim doc As New XmlDocument

doc.Load(Server.MapPath(" Manufacturers.xml))

返回doc


-

John Saunders | MVP - Connected System Developer
>
Code your webmethod as a function returning type System.Xml.XmlDocument.
Then do something like this:

Dim doc As New XmlDocument
doc.Load(Server.MapPath("Manufacturers.xml"))
Return doc

--
John Saunders | MVP - Connected System Developer


" Brock" < wa ******** @ yahoo.com写了留言

新闻:7b ********************** ************ @ i20g2000 prf.googlegroups.com ...
"Brock" <wa********@yahoo.comwrote in message
news:7b**********************************@i20g2000 prf.googlegroups.com...

在你的行中:Dim doc As New XmlDocument" " XmlDocument的"是不是

被接受...应该是XmlDataSource?


In" doc.Load(Server.MapPath(" Manufacturers。) xml"))''我得到'''公开

事件加载(sender As Object,e As System.EventArgs)''是一个事件,而

不能直接打电话。使用''RaiseEvent''语句来举起一个

的事件。


我试了这个但没有运气:
In your line: "Dim doc As New XmlDocument" "XmlDocument" is not
being accepted... should this be "XmlDataSource"?

In "doc.Load(Server.MapPath("Manufacturers.xml")) '' I get "''Public
Event Load(sender As Object, e As System.EventArgs)'' is an event, and
cannot be called directly. Use a ''RaiseEvent'' statement to raise an
event."

I tried this with no luck:



对不起。试试System.Xml.XmlDocument。您可能需要参考System.Xml

汇编。


-

John Saunders | MVP - 连接系统开发人员

Sorry. Try System.Xml.XmlDocument. You may need to reference the System.Xml
assembly.

--
John Saunders | MVP - Connected System Developer


这篇关于Web服务中的xml数据连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆