Академический Документы
Профессиональный Документы
Культура Документы
ftp.cs.sjtu.edu.cn/shen-lp/dotnet/
Contents
Creating an ASP.NET Web Services
WSDL Tool
Proxy Class
Stateful Web Service
ASP.Net1.0 vs. ASP.Net2.0
Final Project
2008-4-21
Creating an ASP.NET Web Services
using System.Web.Services;
WSDL
Courseware.asmx?WSDL
Service Definition(XML)
Proxy
Proxy
DLL
.ASMX
.ASMX
DLL
2008-4-21
@ WebService Directive
Defines XML Web service specific (.asmx file) attributes used
by the ASP.NET parser and compiler.
<%@ WebService attribute="value" [attribute="value"…] %>
Attributes:
• Language: Specifies the language used when compiling all inline code within
the XML Web service file (.asmx).
• CodeBehind :Specifies the source file implementing the XML Web service,
when the class implementing the XML Web service does not reside in the same
file and has not been compiled into an assembly and placed in the \Bin directory.
• Class : Specifies the class implementing the XML Web service that is
automatically compiled the first time the XML Web service is accessed after
changes.
• Debug : Indicates whether the XML Web service should be compiled with
debug symbols
2008-4-21
@ Assembly Directive
Links an assembly to the current page during compilation,
making all the assembly's classes and interfaces available for
use on the page.
Name: The name of the assembly to link to the XML Web service.
Src: The path to a source file to dynamically compile and link against.
Note The path to the assembly or source file in an @ Assembly
directive must be a relative path to the Web application hosting the
XML Web service.
2008-4-21
WebMethod Attribute
2008-4-21
WebService Attribute
2008-4-21
Transport Protocols and Bindings
By default the Web services supports three styles of binding to
the HTTP protocol: SOAP, HTTP GET, and HTTP POST which is
defined in the machine.config file
You can easily specify which protocol bindings your Web service
will support in the web.config file, which locates within the root
directory of the Web application
<system.web> <system.web>
<webServices> <webServices>
<protocols> <protocols>
<remove name="HttpPost"/> <clear/>
<remove name="HttpGet"/> <add name="HttpSoap"/>
<add name="Documentation"/>
</protocols>
</protocols>
</webServices>
2008-4-21 </webServices>
</system.web>
</system.web>
Web Service Documentation
The ASP.NET runtime uses reflection to generate two types of
documentation:
human-readable documentation (.asmx)
documentation used by client applications to interact with the
Web service (.asmx?WSDL)
You can configure ASP.NET to display your custom
documentation when a user navigates to the .asmx file by
setting the wsdlHelpGenerator element within the
configuration file.
<system.web>
<webServices>
<wsdlHelpGenerator href="DefaultWsdlHelpGenerator.aspx" />
</webServices>
2008-4-21
</system.web>
SOAP Encoding Styles
You can set the default encoding style value by decorating the class with
the SoapDocumentService or SoapRpcService attributes which belong to
System.Web.Services.Protocols Namespace.
The SoapRpcService attribute supports only the RoutingStyle property.
Property Description
Specifies whether the parameters are wrapped in a single element within the
ParameterStyle
body of the SOAP message
[SoapDocumentService(SoapBindingUse.Literal,
SoapParameterStyle.Wrapped,
2008-4-21
RoutingStyle=SoapServiceRoutingStyle.SoapAction)]
SOAP Encoding Styles
The SoapDocumentMethod and the SoapRpcMethod attributes are
associated with a particular Web method and can be used to override the
defaults set by their Web service counterparts
The SoapRpcMethod attribute supports the same set of properties minus
the ParameterStyle and Use properties
2008-4-21
Interface Inheritance
An interface defines a contract by which classes that inherit a particular
interface must support all the methods defined by the interface
a Web service interface is defined within a WSDL document. A transport-
specific interface definition is represented by a binding definition, while a
transport-agnostic interface definition is represented by a portType
definition.
How to:
Defines an abstract WebService and WebMethod
Let ASP.NET automatically generate the WSDL file
Remove its service definitions
Use the WebServiceBinding attribute to reference an interface defined within
another namespace
use the Binding property of the SoapDocumentMethod/SoapRpcMethod
attribute to reference the binding defined above
2008-4-21
Interface Inheritance
Limitations:
you can reference only SOAP binding definitions
there is no validation either at compile time or at run time to ensure that the
Web service implements all the methods exposed by the inherited interface
To ensure that the Web service supports all the methods of the inherited
interface, you can use the WSDL.exe tool to generate an abstract class
representing the interface. You can then add the resulting code to your
project and derive from the abstract class instead of the WebService class.
[ WebServiceBinding(Name="RemoteBinding",
Namespace="http://www.contoso.com/MyBinding",
Location="http://www.contoso.com/MySevice.asmx?wsdl")]
public class BindingSample : WebService {
[ SoapDocumentMethod(Binding=“RemoteBinding")]
[ WebMethod() ]
public string BindingMethod() {}
2008-4-21
}
Managing State - Session State
ASP.NET uses a unique identifier that is passed by the client to
identify the session. This identifier can be saved in a cookie
maintained by the client or embedded within the URL of the
request. Even though Web Forms supports both, Web services
support only cookies.
To enable the session state for a web service:
Configure the sessionState element of the machine.config or
web.config configuration file and set the cookieless to false.
Set the EnableSession property of the WebMethod attribute to true
on a per-Web-method basis.
At the client side, set the proxy CookieContainer property.
The Session Object can be got from the Session property of the
WebService Class.
2008-4-21
Managing State - Application State
application state is always handled in process
application state is not dependent on the client supporting cookies.
Example: HitCounter
2008-4-21
Command-Line Switches for
WSDL.exe
2008-4-21
Switch /appsettingurlkey example
To create the proxy:
wsdl /language:CS /namespace:BrokerageFirm
/appsettingurlkey:SecuritiesWebServiceUrl
http://woodgrovebank.com/Securities.asmx?wsdl
2008-4-21
CookieContainer Property
Proxies derived from SoapHttpClientProtocol fully support HTTP
cookies. However, the proxies have cookies disabled by default.
To enable cookie support to maintain session state, you must set
the CookieContainer property on the proxy object to reference an
instance of a CookieContainer object
Once the proxy object has gone out of scope, all cookie
information will be invalid.
2008-4-21
Credentials Property
The Credentials Property is used to hold the credentials when the
authentication mode is Windows.
How to:
Set the mode attribute of <authentication> element in the web.config to
Windows
Set basic/Digest/Windows authentication for the web application in the IIS
administration tool
Get, Store and Transport your credentials with the credentials property of
the proxy class in the client side codes.
2008-4-21
Stateful Grid Service
Hi, I am savas
Banking
savas
Service
Welcome savas
2008-4-21
Grid and Web Services to converge
Web Services: applications on-demand
Grid: computer-resources on-demand
WS Resource Framework specification: defines
how to access stateful computer-resources (WS
resource) through a web service
WSRF.NET: WSRF implementation on .NET
platform
http://www.cs.virginia.edu/~gsw2c/wsrf.net.html
2008-4-21