Web Services Örnekleri
- Önceki Sayfa WS Platformu
- Sonraki Sayfa WS Kullanımı
Herhangi bir uygulama Web Service bileşeni sahip olabilir.
Web Service'lerin oluşturulması ve programlama dilinin türü ile ilgilidir.
Bir örnek: ASP.NET Web Service
Bu örnekte, ASP.NET kullanarak basit bir Web Service oluşturacağız.
<%@ WebService Language="VB" Class="TempConvert" %> Imports System Imports System.Web.Services Public Class TempConvert : Inherits WebService <WebMethod()> Public Function FahrenheitToCelsius (ByVal Fahrenheit As Int16) As Int16 Dim celsius As Int16 celsius = ((((Fahrenheit) - 32) / 9) * 5) Return celsius End Function <WebMethod()> Public Function CelsiusToFahrenheit (ByVal Celsius As Int16) As Int16 Dim fahrenheit As Int16 fahrenheit = ((((Celsius) * 9) / 5) + 32) Return fahrenheit End Function End Class
Bu belge bir .asmx dosyasıdır. Bu, XML Web Services için kullanılan ASP.NET dosya uzantısıdır.
Bu örneği çalıştırmak için bir .NET sunucusuna ihtiyacımız var
Bu belgedeki ilk satır, bu belgenin bir Web Service olduğunu ve VB ile yazıldığını, sınıf adının "TempConvert" olduğunu gösterir.
<%@ WebService Language="VB" Class="TempConvert" %>
Sonraki kod satırları .NET çerçevesinden "System.Web.Services" adlı alan adını içe aktarır.
Imports System Imports System.Web.Services
Aşağıdaki satır "TempConvert" sınıfının bir WebSerivce sınıfı olduğunu tanımlar:
Public Class TempConvert : Inherits WebService
Sonraki adımlar temel VB programlamadır. Bu uygulama iki fonksiyon içerir. Birisi Fahrenhayt'i Santigrad'a dönüştürür, diğeri ise Santigrad'ı Fahrenhayt'e dönüştürür.
Bu fonksiyonun tek farkı, "WebMethod" olarak tanımlanmış olmasıdır.
Lütfen web services olarak kullanmak istediğiniz uygulamanızda "WebMethod" ile işaretlenmiş fonksiyonu kullanın.
<WebMethod()> Public Function FahrenheitToCelsius (ByVal Fahrenheit As Int16) As Int16 Dim celsius As Int16 celsius = ((((Fahrenheit) - 32) / 9) * 5) Return celsius End Function <WebMethod()> Public Function CelsiusToFahrenheit (ByVal Celsius As Int16) As Int16 Dim fahrenheit As Int16 fahrenheit = ((((Celsius) * 9) / 5) + 32) Return fahrenheit End Function
Son olarak yapmanız gereken şey, fonksiyon ve sınıfları sonlandırmaktır:
End Function End Class
Bu dosyayı .asmx dosyası olarak kaydedip .NET destekli bir sunucuda yayınlarsanız, ilk çalışan Web Service'inizi elde etmiş olursunuz.
ASP.NET Otomatik İşleme
ASP.NET ile, WSDL ve SOAP belgelerini kendiniz yazmanıza gerek yok.
Bu örneği dikkatlice inceleyirseniz, ASP.NET'in WSDL ve SOAP isteklerini otomatik olarak oluşturduğunu göreceksiniz.
- Önceki Sayfa WS Platformu
- Sonraki Sayfa WS Kullanımı