开发者

Can we expose public properties of a webservice on the client side?

I understand that webservices are stateless. I want to know if there is any way we can expose the public properties (getters and setters) of a webservice on the client side (client side being a vb consumer not javascr开发者_开发问答ipt)?


Web services are method-based, so they're not designed to access properties.

But there's no reason you couldn't make GetX/SetX methods which are exposed like regular service methods - just make sure you include the [WebMethod] attribute.


As others have suggested, you will need to use get/set methods instead of properties.

As for accessing the web service from JavaScript, just specify the method name in the URL and do an XmlHttpRequest.


The only thing you can "expose" from a web service are the [WebMethod].


You might access your web service with code like the following:

Dim svc as New WebReference.MyWebService()
Dim result As Integer = svc.GetSomeInteger()
svc.SetSomeInteger(result)
Dim result2 As Integer = svc.GetSomeInteger()

You may think that you have created an instance of the web service class. You have not. You have only created an instance of the proxy class in your VB.NET code. In the above code, each call to the web service goes through the same client proxy instance, but will go to a different instance of the server-side web service class.

Even if the web service had properties, or just fields, since you would have a different instance of the web service for each call, you would have a different version of "SomeInteger" each time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜