5. ทดสอบ webservices ในอินเทอร์เน็ต (webservicex.net)
- ทดสอบกับ webservices.net ได้แฟ้ม CurrencyConvertor.cs ขนาด 10,528 Bytes
- ตัวอย่าง currencyconvertor.aspx และ biblewebservice.aspx
5.1 การแปลงหน่วยแลกเปลี่ยนเงิน (สั่ง wsdl หลายครั้ง กว่าจะเชื่อมต่อสำเร็จ ก็ได้ในครั้งสุดท้าย)
cd C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin
wsdl http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
dir CurrencyConvertor.cs
copy CurrencyConvertor.cs %windir%\Microsoft.NET\Framework\v2.0.50727\
cd %windir%\Microsoft.NET\Framework\v2.0.50727\
csc /out:CurrencyConvertor.dll /t:library /r:System.dll /r:System.Web.Services.dll CurrencyConvertor.cs
แล้วคัดลอกแฟ้ม CurrencyConvertor.dll ไปไว้ในห้อง Bin
5.2 ข้อมูลใน bible GetBibleWordsByChapterAndVerse
cd C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin
wsdl http://www.webservicex.com/BibleWebservice.asmx?WSDL
dir BibleWebservice.cs
copy BibleWebservice.cs %windir%\Microsoft.NET\Framework\v2.0.50727\
cd %windir%\Microsoft.NET\Framework\v2.0.50727\
csc /out:BibleWebservice.dll /t:library /r:System.dll /r:System.Web.Services.dll BibleWebservice.cs
แล้วคัดลอกแฟ้ม BibleWebservice.dll ไปไว้ในห้อง Bin
Classic ASP มีตัวอย่างที่ http://www.thaiabc.com/aspnet/biblewebservice.aspx
<%@ Import Namespace="BibleWebservice" %>
<%
Dim c As New BibleWebservice
dim txt as String
txt = c.GetBibleWordsByChapterAndVerse("Exodus",1,1)
response.write(txt)
txt = c.GetBibleWordsByChapterAndVerse("Exodus",1,2)
response.write(txt)
response.write(c.GetBibleWordsByChapterAndVerse("Exodus",1,3))
response.write(c.GetBibleWordsByChapterAndVerse("Exodus",1,4))
%>
|
|
99.1. ตัวอย่าง จาก http://samples.gotdotnet.com (เว็บไซต์ shutdown ไปแล้ว)
1 DOS>cd "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\"
2 DOS>wsdl http://samples.gotdotnet.com/.../MathService.asmx?WSDL
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\MathService.cs'.
3 DOS>copy MathService.cs C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
4 DOS>cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
5 DOS>csc /out:MathService.dll /t:library /r:System.dll /r:System.Web.Services.dll MathService.cs
6 DOS>mkdir C:\website7\bin
7 DOS>copy mathservice.dll C:\website7\bin
Imports System
Imports System.Web.Services
Public Class MathService : Inherits WebService
<WebMethod()> Public Function Add(a As Integer, b As Integer) As Integer
Return(a + b)
End Function
End Class
<%@ Import Namespace="mathservice" %>
<%
Dim a As New MathService
Response.Write(a.Add(1, 2))
%>
|
99.2. ตัวอย่าง การเรียกใช้ webservice ของกรมสรรพากร
+ Client Certificate http://www.rd.go.th/webservice/new/certificate_291150.cer
+ Information http://www.rd.go.th/webservice/new/tin.html
+ URL OF WSDL https://rdws.rd.go.th/ServiceRD/CheckTINPINService.asmx?WSDL
+ to setup Certificate http://support.microsoft.com/kb/307267
1. Repeat the preceding first 2 steps, click Download CA certificate, and then save it to a file on your local computer.
2. Start mmc.exe.
3. Click Console, and then click Add/Remove Snap-in.
4. In the Add/Remove Snap-in dialog box, click Add.
5. In the Add Standalone Snap-in dialog box, click Certificates, and then click Add.
6. Click Computer Account, and then click Next.
7. Click Local Computer, and then click Finish.
8. The list of certificate categories for the local computer should appear in the snap-in window.
9. Click OK to return to the Console Root window.
10. In the tree view, open the list of trusted root certificate authorities.
11. To add the certificate authority certificate that issued your server certificate
to the list, click Action, click All Tasks, and then click Import, or drag the certificate on to the list.
99.3 สร้าง proxy.bat จะได้สร้าง CheckTINPINService.dll ได้ง่าย
+ ถ้าแฟ้ม .aspx เป็นห้องใด ก็ให้เปลี่ยน C:\website9 เป็นห้องนั้น
+ 530117 : พบปัญหาตอนใช้ wsdl ว่า The remote certificate is invalid according จึงไม่ได้แฟ้ม .cs ครับ
rem proxy.bat
set curdir=C:\website9
cd "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\"
wsdl https://rdws.rd.go.th/ServiceRD/CheckTINPINService.asmx?WSDL
copy CheckTINPINService.cs %windir%\Microsoft.NET\Framework\v2.0.50727\
cd %windir%\Microsoft.NET\Framework\v2.0.50727\
csc /out:CheckTINPINService.dll /t:library /r:System.dll /r:System.Web.Services.dll CheckTINPINService.cs
mkdir %curdir%\bin
copy CheckTINPINService.dll %curdir%bin
cd %curdir%
99.4. ตัวอย่าง Code ส่วนหนึ่งของแฟ้ม .aspx
<%@ Import Namespace="CheckTINPINService" %>
<%
Dim DS As New Data.DataSet()
Dim a As New CheckTINPINService
' ServicePIN("username", "password", "PIN")
DS = a.ServicePIN("anonymous", "anonymous", 3520300266740)
Dim I, j, k As Integer
Dim s As String = ""
For I = 0 To DS.Tables.Count - 1
For j = 0 To DS.Tables(I).Rows.Count - 1
For k = 0 To DS.Tables(I).Columns.Count - 1
s &= DS.Tables(I).Rows(j).Item(k) & " "
Next
s &= "<br>"
Next
Next
Response.Write(s)
' E00002 ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้องหรือไม่มีสิทธิในการเรียกใช้ Service Username or Password are invalid
' 3520300266740 True W00000(การทำงานเสร็จสมบูรณ์) Success
|