注:web服务简介Webservices-1.web服务定义简介
以下均以C#语言为例
一、创建web服务(简单介绍,主要讨论客户端引用)
打开VS创建网站项目,在网站项目中添加“WEB服务(ASMX)”,
此时VS便已经默认建立好一个web服务。
如需使用Session,请添加“[WebMethod(EnableSession=true)] ”,更多信息请实际编写代码时候查看智能提示,及msdn文档
此时可以将服务部署于web服务器上,以IIS为例,部署完毕即可正确访问。有时创建IIS网站时,请注意配置使用的.net版本库。
访问地址:http://172.168.0.40:8086/WebSer.asmx(个人PC示例,请勿随意copy)
二、服务解析概述
在访问地址后添加?WSDL既可以查看服务说明文档:http://172.168.0.40:8086/WebSer.asmx?WSDL
1 <?xml version="1.0" encoding="utf-8"?> 2 <wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="ChineShine" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="ChineShine" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> 3 <wsdl:types> 4 <s:schema elementFormDefault="qualified" targetNamespace="ChineShine"> 5 <s:element name="HelloWorld"> 6 <s:complexType> 7 <s:sequence> 8 <s:element minOccurs="0" maxOccurs="1" name="ss" type="s:string" /> 9 </s:sequence> 10 </s:complexType> 11 </s:element> 12 <s:element name="HelloWorldResponse"> 13 <s:complexType> 14 <s:sequence> 15 <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" /> 16 </s:sequence> 17 </s:complexType> 18 </s:element> 19 <s:element name="NoReturnValue"> 20 <s:complexType> 21 <s:sequence> 22 <s:element minOccurs="0" maxOccurs="1" name="ss" type="s:string" /> 23 </s:sequence> 24 </s:complexType> 25 </s:element> 26 <s:element name="NoReturnValueResponse"> 27 <s:complexType /> 28 </s:element> 29 <s:element name="NoParaValue"> 30 <s:complexType /> 31 </s:element> 32 <s:element name="NoParaValueResponse"> 33 <s:complexType> 34 <s:sequence> 35 <s:element minOccurs="0" maxOccurs="1" name="NoParaValueResult" type="s:string" /> 36 </s:sequence> 37 </s:complexType> 38 </s:element> 39 </s:schema> 40 </wsdl:types> 41 <wsdl:message name="HelloWorldSoapIn"> 42 <wsdl:part name="parameters" element="tns:HelloWorld" /> 43 </wsdl:message> 44 <wsdl:message name="HelloWorldSoapOut"> 45 <wsdl:part name="parameters" element="tns:HelloWorldResponse" /> 46 </wsdl:message> 47 <wsdl:message name="NoReturnValueSoapIn"> 48 <wsdl:part name="parameters" element="tns:NoReturnValue" /> 49 </wsdl:message> 50 <wsdl:message name="NoReturnValueSoapOut"> 51 <wsdl:part name="parameters" element="tns:NoReturnValueResponse" /> 52 </wsdl:message> 53 <wsdl:message name="NoParaValueSoapIn"> 54 <wsdl:part name="parameters" element="tns:NoParaValue" /> 55 </wsdl:message> 56 <wsdl:message name="NoParaValueSoapOut"> 57 <wsdl:part name="parameters" element="tns:NoParaValueResponse" /> 58 </wsdl:message> 59 <wsdl:portType name="WebSerSoap"> 60 <wsdl:operation name="HelloWorld"> 61 <wsdl:input message="tns:HelloWorldSoapIn" /> 62 <wsdl:output message="tns:HelloWorldSoapOut" /> 63 </wsdl:operation> 64 <wsdl:operation name="NoReturnValue"> 65 <wsdl:input message="tns:NoReturnValueSoapIn" /> 66 <wsdl:output message="tns:NoReturnValueSoapOut" /> 67 </wsdl:operation> 68 <wsdl:operation name="NoParaValue"> 69 <wsdl:input message="tns:NoParaValueSoapIn" /> 70 <wsdl:output message="tns:NoParaValueSoapOut" /> 71 </wsdl:operation> 72 </wsdl:portType> 73 <wsdl:binding name="WebSerSoap" type="tns:WebSerSoap"> 74 <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 75 <wsdl:operation name="HelloWorld"> 76 <soap:operation soapAction="ChineShine/HelloWorld" style="document" /> 77 <wsdl:input> 78 <soap:body use="literal" /> 79 </wsdl:input> 80 <wsdl:output> 81 <soap:body use="literal" /> 82 </wsdl:output> 83 </wsdl:operation> 84 <wsdl:operation name="NoReturnValue"> 85 <soap:operation soapAction="ChineShine/NoReturnValue" style="document" /> 86 <wsdl:input> 87 <soap:body use="literal" /> 88 </wsdl:input> 89 <wsdl:output> 90 <soap:body use="literal" /> 91 </wsdl:output> 92 </wsdl:operation> 93 <wsdl:operation name="NoParaValue"> 94 <soap:operation soapAction="ChineShine/NoParaValue" style="document" /> 95 <wsdl:input> 96 <soap:body use="literal" /> 97 </wsdl:input> 98 <wsdl:output> 99 <soap:body use="literal" /> 100 </wsdl:output> 101 </wsdl:operation> 102 </wsdl:binding> 103 <wsdl:binding name="WebSerSoap12" type="tns:WebSerSoap"> 104 <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /> 105 <wsdl:operation name="HelloWorld"> 106 <soap12:operation soapAction="ChineShine/HelloWorld" style="document" /> 107 <wsdl:input> 108 <soap12:body use="literal" /> 109 </wsdl:input> 110 <wsdl:output> 111 <soap12:body use="literal" /> 112 </wsdl:output> 113 </wsdl:operation> 114 <wsdl:operation name="NoReturnValue"> 115 <soap12:operation soapAction="ChineShine/NoReturnValue" style="document" /> 116 <wsdl:input> 117 <soap12:body use="literal" /> 118 </wsdl:input> 119 <wsdl:output> 120 <soap12:body use="literal" /> 121 </wsdl:output> 122 </wsdl:operation> 123 <wsdl:operation name="NoParaValue"> 124 <soap12:operation soapAction="ChineShine/NoParaValue" style="document" /> 125 <wsdl:input> 126 <soap12:body use="literal" /> 127 </wsdl:input> 128 <wsdl:output> 129 <soap12:body use="literal" /> 130 </wsdl:output> 131 </wsdl:operation> 132 </wsdl:binding> 133 <wsdl:service name="WebSer"> 134 <wsdl:port name="WebSerSoap" binding="tns:WebSerSoap"> 135 <soap:address location="http://172.168.0.40:8086/WebSer.asmx" /> 136 </wsdl:port> 137 <wsdl:port name="WebSerSoap12" binding="tns:WebSerSoap12"> 138 <soap12:address location="http://172.168.0.40:8086/WebSer.asmx" /> 139 </wsdl:port> 140 </wsdl:service> 141 </wsdl:definitions>