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

vivek 2008-01-14 10: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>



...全文
201 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
weilu0328 2008-01-30
  • 打赏
  • 举报
回复
LZ可以找些例子把Web Service写好,然后在你本地的IIS上发布出来,别人去访问发布出来的WenService
看看能不能访问到。
如果能的话,以后就在你写的.Net程式里去添加Web引用,这样你在所写的程式里就可以用这样的WebService撒!
我也不是特别深入了解WebService其中的奥妙,希望能对LZ有所帮助,共同进步。
haso168 2008-01-30
  • 打赏
  • 举报
回复
LZ,你的问题解决了吗?我也和你遇到了差不多的情况!
china0308 2008-01-17
  • 打赏
  • 举报
回复
到我的资源里下web service例子看看,很简单,如果看懂了,再做就容易了
heqi915 2008-01-17
  • 打赏
  • 举报
回复
友情MARK
vivek 2008-01-15
  • 打赏
  • 举报
回复
楼上说的,我不太明白呢,我初学.net
changjiangzhibin 2008-01-15
  • 打赏
  • 举报
回复
试着在Web Service里写个方法,在另一个类里调用它,
完成了就可以按你的意愿去操作它了
vivek 2008-01-15
  • 打赏
  • 举报
回复
找了,主要是不知道怎么按他的需求写
cloudgamer 2008-01-15
  • 打赏
  • 举报
回复
可以找些例子看啊


diy520
rangeon 2008-01-14
  • 打赏
  • 举报
回复
帮顶
vivek 2008-01-14
  • 打赏
  • 举报
回复
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>

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧