编写一个简单的Web服务 [英] Writing a simple webservice

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

问题描述



大家好,我正在寻求在VB.NET中开发一个简单的Web服务,但是我有一些微不足道的问题。在Visual Studio中,我创建一个Web服务

项目并将asmx.vb文件更改为:


Imports System.Web.Services

Imports System.Web.Services.Protocols

Imports System.ComponentModel

< System.Web.Services.WebService(Namespace:=" http://

wwwpreview。#deleted#.co.uk / ~ptaylor / Customer.wsdl")_

< System.Web.Services.WebServiceBinding(ConformsTo := WsiProfiles.BasicProfile1_1)>

_

< ToolboxItem(False)_

公共类CustomerService

继承System.Web.Services.WebService


< WebMethod()_

公共函数getCustomer()As TreeObject()


Dim t1 As New TreeObject

Dim t2 As New TreeObject

Dim t3 As New TreeObject


Dim arr(2)作为TreeObject

arr(0)= t1

arr(1)= t2

arr(2)= t3


返回arr

结束功能


结束类


如你所见,我的函数返回一个类型为TreeObject的对象。并且

当你运行它时它有效。客户端显然返回一个数组

3个TreeObjects对象。但是我实际上无法在这些树对象上调用任何函数

。这是TreeObject的当前定义:


Imports System.Web.Services


< System.Serializable()_

Public Class TreeObject


Public Sub New()


End Sub


< WebMethod()_

Public Sub setId(ByVal id As Int32)


End Sub


< ; WebMethod()_

公共函数getId()As String

返回1

结束函数


< WebMethod()_

Public Sub setName(ByVal value As String)

End Sub


< WebMethod ()_

公共函数getName()As String

返回boo ya

结束函数


结束类


但是函数GetName,SetName,GetId,SetId没有出现在

的WSDL文件中,并且函数不能从客户端。 (我认为
认为TreeObject没有继承自

对象的功能)


如何使这些功能可以访问?我需要设置

另一个服务吗?或者什么?


谢谢


Phill

解决方案

在6 maio,11:23,Phillip Taylor< Phillip.Ross.Tay ... @ gmail.com>

写道:

$ b $嗨大家好,我正在寻求在VB.NET中开发一个简单的Web服务,但是我有一些微不足道的问题。在Visual Studio中,我创建一个Web服务

项目并将asmx.vb文件更改为:


Imports System.Web.Services

Imports System.Web.Services.Protocols

Imports System.ComponentModel

< System.Web.Services.WebService(Namespace:=" http://

wwwpreview。#deleted#.co.uk / ~ptaylor / Customer.wsdl")_

< System.Web.Services.WebServiceBinding(ConformsTo := WsiProfiles.BasicProfile1_1)>

_

< ToolboxItem(False)_

公共类CustomerService

继承System.Web.Services.WebService


< WebMethod()_

公共函数getCustomer()As TreeObject()


Dim t1 As New TreeObject

Dim t2 As New TreeObject

Dim t3 As New TreeObject


Dim arr(2)As TreeObject

arr(0)= t1

arr(1)= t2

arr(2)= t3


返回arr

结束功能


结束班级


正如您所看到的,我的函数返回一个类型为TreeObject的对象。并且

当你运行它时它有效。客户端显然返回一个数组

3个TreeObjects对象。但是我实际上无法在这些树对象上调用任何函数

。这是TreeObject的当前定义:


Imports System.Web.Services


< System.Serializable()_

Public Class TreeObject


Public Sub New()


End Sub


< WebMethod()_

Public Sub setId(ByVal id As Int32)


End Sub


< ; WebMethod()_

公共函数getId()As String

返回1

结束函数


< WebMethod()_

Public Sub setName(ByVal value As String)

End Sub


< WebMethod ()_

公共函数getName()As String

返回boo ya

结束函数


结束类


但是函数GetName,SetName,GetId,SetId没有出现在

的WSDL文件中,并且函数不能从客户端。 (我认为
认为TreeObject没有继承自

对象的功能)


如何使这些功能可以访问?我需要设置

另一个服务吗?或者什么?


谢谢


Phill



据我所知,你需要公开公开.asmx中的方法。


5月6日下午4:02,Thiago Macedo< thiago.ch ... @ gmail.comwrote:


6 maio,11:23,Phillip Taylor< Phillip.Ross.Tay ... @ gmail.com>

写道:


大家好,我正在寻找在VB.NET中开发一个简单的Web服务,但是我有一些b $ b琐碎的问题。在Visual Studio中,我创建一个Web服务

项目并将asmx.vb文件更改为:


Imports System。 Web.Services

Imports System.Web.Services.Protocols

Imports System.ComponentModel


< System.Web.Services.WebService(Namespace:=" http://

wwwpreview。#deleted#.co.uk / ~ptaylor / Customer.wsdl")_

< System.Web.Services.WebServiceBinding(ConformsTo:= WsiProfiles.BasicProfile1_1)>

_

< ToolboxItem(False)_

公共类CustomerService

继承System.Web.Services.WebService


< WebMethod() _

公共函数getCustomer()As TreeObject()


Dim t1 As New TreeObject

Dim t2 As New TreeObject

Dim t3 As New TreeObject


Dim arr(2)As TreeObject

arr (0)= t1

arr(1)= t2

arr(2)= t3


返回arr

结束函数


结束类


正如你所看到的,我的函数返回一个类型为TreeObject的对象。并且

当你运行它时它有效。客户端显然返回一个数组

3个TreeObjects对象。但是我实际上无法在这些树对象上调用任何函数

。这是TreeObject的当前定义:


Imports System.Web.Services


< System.Serializable()_

公共类TreeObject


Public Sub New()


End Sub


< WebMethod()_

Public Sub setId(ByVal id As Int32)


End Sub


< WebMethod()_

公共函数getId()As String

返回1

结束函数


< WebMethod()_

Public Sub setName(ByVal value As String)

End Sub


< WebMethod()_

公共函数getName()As String

返回" boo ya"

结束函数


结束类


但是函数GetName,SetName,GetId,SetId没有出现在WSDL文件中,而且函数不能从客户端访问。 (我认为
认为TreeObject没有继承自

对象的函数)


如何使这些功能可以访问?我需要设置

另一个服务吗?或者是什么?


谢谢


Phill



据我所知,你需要公开公开.asmx中的方法。



这就是我认为添加< WebMethod()_所做的一切,但是

它似乎没有只需它就足够了。


Phillip Taylor写道:


>

< WebMethod()_

公共函数getCustomer()As TreeObject()


Dim t1 As New TreeObject

Dim t2 As New TreeObject

Dim t3 As New TreeObject


Dim arr(2)As TreeObject

arr(0 )= t1

arr(1)= t2

arr(2)= t3


返回arr

结束函数


结束类


如你所见,我的函数返回一个类型为TreeObject的对象。并且

当你运行它时它有效。客户端显然返回一个数组

3个TreeObjects对象。但是我实际上无法在这些树对象上调用任何函数

。这是TreeObject的当前定义:



当WebService将一个Object返回给调用程序时,它发送所需的

数据创造这样一个对象。数据以XML格式传递。对于要使用它的

调用程序,它必须具有该对象的类定义

。然后它创建该类的新实例,并使用从Web服务接收的数据来初始化它。没有任何意义,你实际上是在向调用程序发送功能对象。


通常你会有一个dll或类似的定义类,

属性标识为可序列化,Web服务和

调用程序都使用它。当要求Web服务返回此

类的实例时,它将XML作为可序列化属性的值返回。然后

调用程序创建同一个类的实例,并使用序列化的

XML数据使其与Web服务使用的相同。


一个很好的例子是数据集,这是一个Web服务和调用

程序都可以创建的类。然后,可以使用Web服务在客户端上的数据集和服务器上的数据集之间来回传递数据序列化为

XML。



Hi guys, I''m looking to develop a simple web service in VB.NET but I''m
having some trivial issues. In Visual Studio I create a web services
project and change the asmx.vb file to this:

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

<System.Web.Services.WebService(Namespace:="http ://
wwwpreview.#deleted#.co.uk/~ptaylor/Customer.wsdl")_
<System.Web.Services.WebServiceBinding(ConformsTo: =WsiProfiles.BasicProfile1_1)>
_
<ToolboxItem(False)_
Public Class CustomerService
Inherits System.Web.Services.WebService

<WebMethod()_
Public Function getCustomer() As TreeObject()

Dim t1 As New TreeObject
Dim t2 As New TreeObject
Dim t3 As New TreeObject

Dim arr(2) As TreeObject
arr(0) = t1
arr(1) = t2
arr(2) = t3

Return arr
End Function

End Class

As you can see my function returns an object of type "TreeObject" and
when you run this it works. the clients are clearly returned an array
3 TreeObjects objects. However I cannot actually invoke any functions
on these tree objects. This is the current definition of TreeObject:

Imports System.Web.Services

<System.Serializable()_
Public Class TreeObject

Public Sub New()

End Sub

<WebMethod()_
Public Sub setId(ByVal id As Int32)

End Sub

<WebMethod()_
Public Function getId() As String
Return 1
End Function

<WebMethod()_
Public Sub setName(ByVal value As String)
End Sub

<WebMethod()_
Public Function getName() As String
Return "boo ya"
End Function

End Class

However the functions GetName, SetName, GetId, SetId do not appear in
the WSDL file and the functions are not accessable from the client. (I
think TreeObject has no functions other than those inherited from
Object)

How do I make those functions accessible please? Do I need to set up
another "service" or what?

Thanks

Phill

解决方案

On 6 maio, 11:23, Phillip Taylor <Phillip.Ross.Tay...@gmail.com>
wrote:

Hi guys, I''m looking to develop a simple web service in VB.NET but I''m
having some trivial issues. In Visual Studio I create a web services
project and change the asmx.vb file to this:

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

<System.Web.Services.WebService(Namespace:="http ://
wwwpreview.#deleted#.co.uk/~ptaylor/Customer.wsdl")_
<System.Web.Services.WebServiceBinding(ConformsTo: =WsiProfiles.BasicProfile1_1)>
_
<ToolboxItem(False)_
Public Class CustomerService
Inherits System.Web.Services.WebService

<WebMethod()_
Public Function getCustomer() As TreeObject()

Dim t1 As New TreeObject
Dim t2 As New TreeObject
Dim t3 As New TreeObject

Dim arr(2) As TreeObject
arr(0) = t1
arr(1) = t2
arr(2) = t3

Return arr
End Function

End Class

As you can see my function returns an object of type "TreeObject" and
when you run this it works. the clients are clearly returned an array
3 TreeObjects objects. However I cannot actually invoke any functions
on these tree objects. This is the current definition of TreeObject:

Imports System.Web.Services

<System.Serializable()_
Public Class TreeObject

Public Sub New()

End Sub

<WebMethod()_
Public Sub setId(ByVal id As Int32)

End Sub

<WebMethod()_
Public Function getId() As String
Return 1
End Function

<WebMethod()_
Public Sub setName(ByVal value As String)
End Sub

<WebMethod()_
Public Function getName() As String
Return "boo ya"
End Function

End Class

However the functions GetName, SetName, GetId, SetId do not appear in
the WSDL file and the functions are not accessable from the client. (I
think TreeObject has no functions other than those inherited from
Object)

How do I make those functions accessible please? Do I need to set up
another "service" or what?

Thanks

Phill

As I know, you need to public expose the methods in the .asmx.


On May 6, 4:02 pm, Thiago Macedo <thiago.ch...@gmail.comwrote:

On 6 maio, 11:23, Phillip Taylor <Phillip.Ross.Tay...@gmail.com>
wrote:

Hi guys, I''m looking to develop a simple web service in VB.NET but I''m
having some trivial issues. In Visual Studio I create a web services
project and change the asmx.vb file to this:

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

<System.Web.Services.WebService(Namespace:="http ://
wwwpreview.#deleted#.co.uk/~ptaylor/Customer.wsdl")_
<System.Web.Services.WebServiceBinding(ConformsTo: =WsiProfiles.BasicProfile1_1)>
_
<ToolboxItem(False)_
Public Class CustomerService
Inherits System.Web.Services.WebService

<WebMethod()_
Public Function getCustomer() As TreeObject()

Dim t1 As New TreeObject
Dim t2 As New TreeObject
Dim t3 As New TreeObject

Dim arr(2) As TreeObject
arr(0) = t1
arr(1) = t2
arr(2) = t3

Return arr
End Function

End Class

As you can see my function returns an object of type "TreeObject" and
when you run this it works. the clients are clearly returned an array
3 TreeObjects objects. However I cannot actually invoke any functions
on these tree objects. This is the current definition of TreeObject:

Imports System.Web.Services

<System.Serializable()_
Public Class TreeObject

Public Sub New()

End Sub

<WebMethod()_
Public Sub setId(ByVal id As Int32)

End Sub

<WebMethod()_
Public Function getId() As String
Return 1
End Function

<WebMethod()_
Public Sub setName(ByVal value As String)
End Sub

<WebMethod()_
Public Function getName() As String
Return "boo ya"
End Function

End Class

However the functions GetName, SetName, GetId, SetId do not appear in
the WSDL file and the functions are not accessable from the client. (I
think TreeObject has no functions other than those inherited from
Object)

How do I make those functions accessible please? Do I need to set up
another "service" or what?

Thanks

Phill


As I know, you need to public expose the methods in the .asmx.

That''s what I thought adding <WebMethod ()_ to everything did, but
it doesn''t seem to be enough on it''s own.


Phillip Taylor wrote:

>
<WebMethod()_
Public Function getCustomer() As TreeObject()

Dim t1 As New TreeObject
Dim t2 As New TreeObject
Dim t3 As New TreeObject

Dim arr(2) As TreeObject
arr(0) = t1
arr(1) = t2
arr(2) = t3

Return arr
End Function

End Class

As you can see my function returns an object of type "TreeObject" and
when you run this it works. the clients are clearly returned an array
3 TreeObjects objects. However I cannot actually invoke any functions
on these tree objects. This is the current definition of TreeObject:

When a WebService returns an Object to the calling program, it is sending the
data needed to create such an object. The data is being passed as XML. For the
calling program to use it, it must have the class definition of that object
available. It then creates a new instance of that class, and uses the data
received from the web service to initialize it. There is no sense in which you
are actually sending a functional object to the calling program.

Typically you would have a dll or similar that defines the class, with
properties identified as serializable, which is used by both the web service and
the calling program. When the web service is asked to return an instance of this
class, it returns as XML the values of the serializable properties. Then the
calling program creates an instance of the same class, and uses the serialized
XML data to make it the same as the one the web service used.

A good example is a Dataset, a class which both the web service and the calling
program can create. The web service can then be used to pass data serialized as
XML back and forth between a Dataset on the client and a Dataset on the server.


这篇关于编写一个简单的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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