初学,给了个描述文件,怎么创建这个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>