您的位置:程序门 -> .net技术 -> web services



请教高手,如何发布 webservices 中的属性?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


请教高手,如何发布 webservices 中的属性?
发表于:2007-12-29 10:17:24 楼主
using   system;
using   system.collections;
using   system.componentmodel;
using   system.data;
using   system.web;
using   system.web.services;
using   system.web.services.protocols;
using   system.xml.serialization;

namespace   webservice1
{
///   <summary>
///   summary   description   for   service1
///   </summary>
[webservice(namespace   =   "http://tempuri.org/")]
[webservicebinding(conformsto   =   wsiprofiles.basicprofile1_1)]
[toolboxitem(false)]
public   class   service1   :   system.web.services.webservice
{
private   int   _para;
[xmlelement("para")]
public   int   para   {   get   {   return   _para;   }   set   {   _para=value;}   }

[webmethod]
public   string   helloworld()
{
return   "hello   world";
}
}
}

我在webservice中定义了一个属性,想把它发布出去,但是不知如何设置,用xmlelement不起作用。请教大家如何实现。
发表于:2007-12-29 13:27:041楼 得分:0
ws追求通用,还达不到这么高的要求。应该发布为:

[webmethod]
public       int       get_para()


[webmethod]
public       void       set_para(int   value)


使用.net和vs开发的ws比许多其它体系(或者语言)开发的ws都更为通用。你可能用.net默认方式开发的ws服务很容易让java客户端使用,反过来则经常发生异常。总之,ws本来就不是那么面向对象。并且开发是也要注意要写出五状态程序才容易实用。
发表于:2007-12-29 14:53:352楼 得分:0
最简单的就是使用楼上的方法   可以将你要进行输出的方法前定义一些变量!
发表于:2008-01-02 23:12:073楼 得分:0
谢谢两位的回复,我这样做的背景是想写一个伪webservice对象代替客户提供的生产环境下的webservice,以便于做测试。

客户的webservice是用java写的,其中公开了一个属性   usertoken。为了不改动调用方的生产环境代码,我也需要在伪webservice对象中公开该属性,所以不能用方法。
发表于:2008-01-02 23:15:014楼 得分:0
大家有什么高见?或者说usertoken(或公开webservice属性)是java对webservice做的非标准扩展,.net不支持?


快速检索

最新资讯
热门点击