XML Web Service
أولا XML Web Service أعتبرها DDL موجودة على النت
فيها Functions وما إلى ذلك بحيث أي شخص يستفيد منها على الانترنت
مثال بسيط جدا جدا
أفتح الدوت نت وأختر ASP.NET Web Service
ثم موافق
ثم أنقر نقرا مزدوجا على النموذج تظهر لك نافذه الكود هذه
Imports System.Web.Services <WebService(Namespace := "http://tempuri.org/")> _ Public Class Service1 Inherits System.Web.Services.WebService #Region " Web Services Designer Generated Code " Public Sub New() MyBase.New() 'This call is required by the Web Services Designer. InitializeComponent() 'Add your own initialization code after the InitializeComponent() call End Sub 'Required by the Web Services Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Web Services Designer 'It can be modified using the Web Services Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container() End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) 'CODEGEN: This procedure is required by the Web Services Designer 'Do not modify it using the code editor. If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub #End Region ' WEB SERVICE EXAMPLE ' The HelloWorld() example service returns the string Hello World. ' To build, uncomment the following lines then save and build the project. ' To test this web service, ensure that the .asmx file is the start page ' and press F5. ' '<WebMethod()> Public Function HelloWorld() As String ' HelloWorld = "Hello World" ' End Function End Class
أكتب الكود
وهي function ما ادري من وين جت على بالي المهم الفكرة
<WebMethod()> Public Function myFunc(ByVal str As String) As String Return str & " : XML Web Server" End Function
أضغط F5
ستظهر لك هذه الصفحه على متصفح الانترنت
Service1
The following operations are supported. For a formal definition, please review the Service Description.
myFunc
--------------------------------------------------------------------------------
This web service is using http://tempuri.org/ as its default namespace.
Recommendation: Change the default namespace before the XML Web service is made public.
Each XML Web service needs a unique namespace in order for client applications to distinguish it from other services on the Web. http://tempuri.org/ is available for XML Web services that are under development, but published XML Web services should use a more permanent namespace.
Your XML Web service should be identified by a namespace that you control. For example, you can use your company's Internet domain name as part of the namespace. Although many XML Web service namespaces look like URLs, they need not point to actual resources on the Web. (XML Web service namespaces are URIs.)
For XML Web services creating using ASP.NET, the default namespace can be changed using the WebService attribute's Namespace property. The WebService attribute is an attribute applied to the class that contains the XML Web service methods. Below is a code example that sets the namespace to "http://microsoft.com/webservices/":
C#
[WebService(Namespace="http://microsoft.com/webservices/")]
public class MyWebService {
// implementation
}
Visual Basic.NET
<WebService(Namespace:="http://microsoft.com/webservices/")> Public Class MyWebService
' implementation
End Class
For more details on XML namespaces, see the W3C recommendation on Namespaces in XML.
For more details on WSDL, see the WSDL Specification.
For more details on URIs, see RFC 2396.http://localhost/WebService1/Service1.asmx
مبروك لقد عملت XML Web Service
أفتح مشروع فيجول بيسك جديد
ضع button على النوذج
ومن قائمة Project أختر Add Web Reference
ثم ضع موقع web service في الشاشة التي ستظهر لك كاملا
وفي برنامج هذا الموقع هو
http://localhost/WebService1/Service1.asmx
ثم أنقر علىadd Reference
سيضع أسمها أفتراضيا localhost
كيفية استخدامها
أنقر على button1
وأكتب الكود التالي
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ws As New localhost.Service1()
MessageBox.Show(ws.myFunc("dotnet4arab"))
End Subثم F5
ثم أنقر على button1
أعذروني إن كان في تقصيير في الشرح ومستعدين للاسئلة
تحياتي