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



初学,给了个描述文件,怎么创建这个web   service?能帮忙写个范例么? 


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


初学,给了个描述文件,怎么创建这个web service?能帮忙写个范例么?
发表于:2008-01-14 22:31:41 楼主

web       service描述          
<?xml       version="1.0"       encoding="utf-8"?>  
<wsdl:definitions       xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"      

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"       xmlns:s="http://www.w3.org/2001/xmlschema"      

xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"       xmlns:tns="http://tempuri.org/"      

xmlns:tm="http://microsoft.com/wsdl/mime/textmatching/"       xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"      

targetnamespace="http://tempuri.org/"       xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">  
        <wsdl:types>  
                <s:schema       elementformdefault="qualified"       targetnamespace="http://tempuri.org/">  
                        <s:element       name="getspservices">  
                                <s:complextype       />  
                        </s:element>  
                        <s:element       name="getspservicesresponse">  
                                <s:complextype>  
                                        <s:sequence>  
                                            <s:element       minoccurs="0"       maxoccurs="1"       name="getspservicesresult"      

type="tns:arrayofserviceinfo"       />   °  
                                        </s:sequence>  
                                </s:complextype>  
                        </s:element>  
                        <s:complextype       name="arrayofserviceinfo">  
                                <s:sequence>  
                                        <s:element       minoccurs="0"       maxoccurs="unbounded"       name="serviceinfo"       nillable="true"      

type="tns:serviceinfo"       />  
                                </s:sequence>  
                        </s:complextype>  
                        <s:complextype       name="serviceinfo">  
                                <s:sequence>  
                                        <s:element       minoccurs="0"       maxoccurs="1"       name="titleurl"       type="s:string"       />  
                                        <s:element       minoccurs="0"       maxoccurs="1"       name="titlename"       type="s:string"       />  
                                        <s:element       minoccurs="0"       maxoccurs="1"       name="titledesc"       type="s:string"       />  
                                </s:sequence>  
                        </s:complextype>  
                </s:schema>  
        </wsdl:types>  
        <wsdl:message       name="getspservicessoapin">  
                <wsdl:part       name="parameters"       element="tns:getspservices"       />  
        </wsdl:message>  
        <wsdl:message       name="getspservicessoapout">  
                <wsdl:part       name="parameters"       element="tns:getspservicesresponse"       />  
        </wsdl:message>  
        <wsdl:porttype       name="spservicesoap">  
                <wsdl:operation       name="getspservices">  
                        <wsdl:input       message="tns:getspservicessoapin"       />  
                        <wsdl:output       message="tns:getspservicessoapout"       />  
                </wsdl:operation>  
        </wsdl:porttype>  
        <wsdl:binding       name="spservicesoap"       type="tns:spservicesoap">  
                <soap:binding       transport="http://schemas.xmlsoap.org/soap/http"       style="document"       />  
                <wsdl:operation       name="getspservices">  
                        <soap:operation       soapaction="http://tempuri.org/getspservices"       style="document"       />  
                        <wsdl:input>  
                                <soap:body       use="literal"       />  
                        </wsdl:input>  
                        <wsdl:output>  
                                <soap:body       use="literal"       />  
                        </wsdl:output>  
                </wsdl:operation>  
        </wsdl:binding>  
        <wsdl:service       name="spservice">  
                <documentation       xmlns="http://schemas.xmlsoap.org/wsdl/"       />  
                <wsdl:port       name="spservicesoap"       binding="tns:spservicesoap">  
                        <soap:address       location="http://localhost:7000/spservice/spservice.asmx"       />  
                </wsdl:port>  
        </wsdl:service>  
</wsdl:definitions>  

webservice       说明:  

service的名称统一为spservice  
<wsdl:service       name="spservice">                                               //这里是service的名称  
                <documentation       xmlns="http://schemas.xmlsoap.org/wsdl/"       />  
                <wsdl:port       name="spservicesoap"       binding="tns:spservicesoap">  
                        <soap:address       location="http://localhost:7000/spservice/spservice.asmx"       />  
                </wsdl:port>  
</wsdl:service>  
取得内容信息的方法命名为getspservices(),无输入参数  
        <wsdl:operation       name="getspservices">                       //这里是方法的名称  
                        <wsdl:input       message="tns:getspservicessoapin"       />  
                        <wsdl:output       message="tns:getspservicessoapout"       />  
                </wsdl:operation>  
返回的数据类型为对象数组,对象的名称统一为serviceinfo  
        <s:element       name="getspservicesresponse">  
                                <s:complextype>  
                                        <s:sequence>  
                                            <s:element       minoccurs="0"       maxoccurs="1"       name="getspservicesresult"      

type="tns:arrayofserviceinfo"       />   °           //返回的数据类型  
                                        </s:sequence>  
                                </s:complextype>  
                        </s:element>  
                        <s:complextype       name="arrayofserviceinfo">  
                                <s:sequence>  
                                        <s:element       minoccurs="0"       maxoccurs="unbounded"       name="serviceinfo"       nillable="true"      

type="tns:serviceinfo"       />               数组的成员类型为serviceinfo的对象  
                                </s:sequence>  
                        </s:complextype>  
代码:  
public       serviceinfo[]       getspservices()  
{  
servicesinfo[]       tempservices       =       …….  
…………..  
return       tempservices;  
}  
对象       serviceinfo的描述如下:          
                        <s:complextype       name="serviceinfo">  
                                <s:sequence>  
                                        <s:element       minoccurs="0"       maxoccurs="1"       name="titleurl"       type="s:string"       />  
                                        <s:element       minoccurs="0"       maxoccurs="1"       name="titlename"       type="s:string"       />  
                                        <s:element       minoccurs="0"       maxoccurs="1"       name="titledesc"       type="s:string"       />  
                                </s:sequence>  
                        </s:complextype>  

 
 
发表于:2008-01-14 22:32:291楼 得分:0
using       system;  
using       system.web;  
using       system.collections;  
using       system.web.services;  
using       system.web.services.protocols;  
using       system.data;  
using       system.data.sqlclient;      

///       <summary>  
///       spservice       的摘要说明  
///       </summary>  
[webservice(namespace       =       "http://123456.com")]  
[webservicebinding(conformsto       =       wsiprofiles.basicprofile1_1)]  
public       class       spservice       :       system.web.services.webservice  
{  


                public       spservice()  
                {  


                                //如果使用设计的组件,请取消注释以下行      
                                //initializecomponent();      
                }  

                [webmethod]  
                public       dataset       getspservices()  
                {  
                                sqlconnection       conn;  
                                conn       =       new       sqlconnection();  
                                conn.connectionstring       =       system.configuration.configurationsettings.appsettings

["connstring"];  
                                try  
                                {  
                                                dataset       ds       =       new       dataset();  
                                                string       searchstring       =       "select       titleurl,titlename,titledesc       from       webservice";  

                                                sqldataadapter       da       =       new       sqldataadapter(searchstring,       conn);  

                                                da.fill(ds,"getspservices");  
                                                return       ds;  

                                }  

                                catch  
                                {  
                                                return       null;  
                                }  

                }  
}  

这是我的代码       不知道怎么按照描述文件里的规则建立该web       service  
         
 
    这是我上面代码调用返回的文档,大概数据结构就是这样      
<?xml       version="1.0"       encoding="utf-8"       ?>      
-       <dataset       xmlns="http://123456.com">  
-       <xs:schema       id="newdataset"       xmlns=""       xmlns:xs="http://www.w3.org/2001/xmlschema"      

xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">  
-       <xs:element       name="newdataset"       msdata:isdataset="true"       msdata:usecurrentlocale="true">  
-       <xs:complextype>  
-       <xs:choice       minoccurs="0"       maxoccurs="unbounded">  
-       <xs:element       name="getspservices">  
-       <xs:complextype>  
-       <xs:sequence>  
        <xs:element       name="titleurl"       type="xs:string"       minoccurs="0"       />      
        <xs:element       name="titlename"       type="xs:string"       minoccurs="0"       />      
        <xs:element       name="titledesc"       type="xs:string"       minoccurs="0"       />      
        </xs:sequence>  
        </xs:complextype>  
        </xs:element>  
        </xs:choice>  
        </xs:complextype>  
        </xs:element>  
        </xs:schema>  
-       <diffgr:diffgram       xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"       xmlns:diffgr="urn:schemas-

microsoft-com:xml-diffgram-v1">  
-       <newdataset       xmlns="">  
-       <getspservices       diffgr:id="getspservices1"       msdata:roworder="0">  
        <titleurl>   url1   </titleurl>      
        <titlename>   【1】   </titlename>      
        <titledesc>   1   </titledesc>      
        </getspservices>  
-       <getspservices       diffgr:id="getspservices2"       msdata:roworder="1">  
        <titleurl>   url2   </titleurl>      
        <titlename>   【2】   </titlename>      
        <titledesc>   2   </titledesc>      
        </getspservices>  
-       <getspservices       diffgr:id="getspservices3"       msdata:roworder="2">  
        <titleurl>   url3   </titleurl>      
        <titlename>   【3】   </titlename>      
        <titledesc>   3   </titledesc>      
        </getspservices>  
        </newdataset>  
        </diffgr:diffgram>  
        </dataset>    
发表于:2008-01-14 22:55:172楼 得分:0
帮顶
发表于:2008-01-15 01:19:173楼 得分:0
可以找些例子看啊


发表于:2008-01-15 09:35:224楼 得分:0
找了,主要是不知道怎么按他的需求写
发表于:2008-01-15 09:41:185楼 得分:0
试着在web   service里写个方法,在另一个类里调用它,
完成了就可以按你的意愿去操作它了
发表于:2008-01-15 09:49:156楼 得分:0
楼上说的,我不太明白呢,我初学.net
发表于:2008-01-15 16:49:107楼 得分:0
或许有用
发表于:2008-01-17 11:53:428楼 得分:0
友情mark
发表于:2008-01-17 12:50:219楼 得分:0
到我的资源里下web   service例子看看,很简单,如果看懂了,再做就容易了


快速检索

最新资讯
热门点击