2011年9月19日 星期一

JavaScript 呼叫 .net寫的 WebService

這篇是更進階的

原始的jsp 呼叫 .net寫的WebService請看這裡
http://savagevb.blogspot.com/2011/09/jsp-net-webservice.html

這裡則是不靠任何jsp內建的語法寫成

原文參這篇,這裡簡單說明

首先下載 JavaScriptSOAPClient_src.zip

解壓縮後,裡面有個 soapclient.js檔案

把他放在網頁同一個目錄

接下來一樣我呼叫 TestHello這個 Function

JavaScript 程式寫著

"<" script type="text/javascript" src="soapclient.js" ">" "<" /script ">"
"<" script language="JavaScript" ">"


function loadService() {
HelloTo();
}
function HelloTo()
{
var pl = new SOAPClientParameters();
pl.add("strName", " Randy");
SOAPClient.invoke("http://172.17.102.209:81/Service1.asmx", "TestHello", pl, true, HelloTo_callBack);
}
function HelloTo_callBack(r)
{
alert(r);
}
"<" /script ">"


這樣就可以了

存檔後執行一遍


 看來是沒問題,不過要注意安全姓的問題

用這個方法WebService 位置會曝光

檢視原始碼


看到了吧,JavaScript把位置都乖乖的講出來了

如果有封Port的話,就更不妙了

方法大家自己決定吧 ^^

2011年9月16日 星期五

把輸出日期變成英文格式

在大企業上班,常常碰到輸出的email需要用英文表示,偏偏公司用中文版的OS,輸出的就是

『九月』,如何把『九月』變成『Sep』
 Date.Now.ToString("MMM", System.Globalization.CultureInfo.GetCultureInfoByIetfLanguageTag("en"))

en可以至換成各國代碼,代碼表在這裡

文化特性名稱
文化特性識別項
語言 - 國家/地區
"" (空字串)
0x007F
不變文化特性 (Invariant Culture)
af
0x0036
南非荷蘭文
af-ZA
0x0436
南非荷蘭文 - 南非
sq
0x001C
阿爾巴尼亞文
sq-AL
0x041C
阿爾巴尼亞文 - 阿爾巴尼亞
ar
0x0001
阿拉伯文
ar-DZ
0x1401
阿拉伯文 - 阿爾及利亞
ar-BH
0x3C01
阿拉伯文 - 巴林
ar-EG
0x0C01
阿拉伯文 - 埃及
ar-IQ
0x0801
阿拉伯文 - 伊拉克
ar-JO
0x2C01
阿拉伯文 - 約旦
ar-KW
0x3401
阿拉伯文 - 科威特
ar-LB
0x3001
阿拉伯文 - 黎巴嫩
ar-LY
0x1001
阿拉伯文 - 利比亞
ar-MA
0x1801
阿拉伯文 - 摩洛哥
ar-OM
0x2001
阿拉伯文 - 阿曼
ar-QA
0x4001
阿拉伯文 - 卡達
ar-SA
0x0401
阿拉伯文 - 沙烏地阿拉伯
ar-SY
0x2801
阿拉伯文 - 敘利亞
ar-TN
0x1C01
阿拉伯文 - 突尼西亞
ar-AE
0x3801
阿拉伯文 - 阿拉伯聯合大公國
ar-YE
0x2401
阿拉伯文 - 葉門
hy
0x002B
亞美尼亞文
hy-AM
0x042B
亞美尼亞文 - 亞美尼亞
az
0x002C
阿澤里文
az-AZ-Cyrl
0x082C
阿澤里文 (斯拉夫) - 亞塞拜然
az-AZ-Latn
0x042C
阿澤里文 (拉丁) - 亞塞拜然
eu
0x002D
巴斯克文
eu-ES
0x042D
巴斯克文 - 巴斯克
be
0x0023
白俄羅斯文
be-BY
0x0423
白俄羅斯文 - 白俄羅斯
bg
0x0002
保加利亞文
bg-BG
0x0402
保加利亞文 - 保加利亞
ca
0x0003
卡達隆尼亞文
ca-ES
0x0403
卡達隆尼亞文 - 西屬卡達隆尼亞
zh-HK
0x0C04
中文 - 香港特別行政區
zh-MO
0x1404
中文 - 澳門特別行政區
zh-CN
0x0804
中文 - 中國
zh-CHS
0x0004
中文 (簡體)
zh-SG
0x1004
中文 - 新加坡
zh-TW
0x0404
中文 - 台灣
zh-CHT
0x7C04
中文 (繁體)
hr
0x001A
克羅埃西亞文
hr-HR
0x041A
克羅埃西亞文 - 克羅埃西亞
cs
0x0005
捷克文
cs-CZ
0x0405
捷克文 - 捷克共和國
da
0x0006
丹麥文
da-DK
0x0406
丹麥文 - 丹麥
div
0x0065
迪維西文
div-MV
0x0465
迪維西文 - 馬爾地夫
nl
0x0013
荷蘭文
nl-BE
0x0813
荷蘭文 - 比利時
nl-NL
0x0413
荷蘭文 - 荷蘭
en
0x0009
英文
en-AU
0x0C09
英文 - 澳大利亞
en-BZ
0x2809
英文 - 貝里斯
en-CA
0x1009
英文 - 加拿大
en-CB
0x2409
英文 - 加勒比海
en-IE
0x1809
英文 - 愛爾蘭
en-JM
0x2009
英文 - 牙買加
en-NZ
0x1409
英文 - 紐西蘭
en-PH
0x3409
英文 - 菲律賓
en-ZA
0x1C09
英文 - 南非
en-TT
0x2C09
英文 - 千里達及托巴哥
en-GB
0x0809
英文 - 英國
en-US
0x0409
英文 - 美國
en-ZW
0x3009
英文 - 辛巴威
et
0x0025
愛沙尼亞文
et-EE
0x0425
愛沙尼亞文 - 愛沙尼亞
fo
0x0038
法羅文
fo-FO
0x0438
法羅文 - 法羅群島
fa
0x0029
波斯文
fa-IR
0x0429
波斯文 - 伊朗
fi
0x000B
芬蘭文
fi-FI
0x040B
芬蘭文 - 芬蘭
fr
0x000C
法文
fr-BE
0x080C
法文 - 比利時
fr-CA
0x0C0C
法文 - 加拿大
fr-FR
0x040C
法文 - 法國
fr-LU
0x140C
法文 - 盧森堡
fr-MC
0x180C
法文 - 摩納哥
fr-CH
0x100C
法文 - 瑞士
gl
0x0056
加里斯亞文
gl-ES
0x0456
加里斯亞文 - 西屬加里斯亞
ka
0x0037
喬治亞文
ka-GE
0x0437
喬治亞文 - 喬治亞
de
0x0007
德文
de-AT
0x0C07
德文 - 奧地利
de-DE
0x0407
德文 - 德國
de-LI
0x1407
德文 - 列支敦斯登
de-LU
0x1007
德文 - 盧森堡
de-CH
0x0807
德文 - 瑞士
el
0x0008
希臘文
el-GR
0x0408
希臘文 - 希臘
gu
0x0047
古吉拉特文
gu-IN
0x0447
古吉拉特文 - 印度
he
0x000D
希伯來文
he-IL
0x040D
希伯來文 - 以色列
hi
0x0039
印度文
hi-IN
0x0439
印度文 - 印度
hu
0x000E
匈牙利文
hu-HU
0x040E
匈牙利文 - 匈牙利
is
0x000F
冰島文
is-IS
0x040F
冰島文 - 冰島
id
0x0021
印尼文
id-ID
0x0421
印尼文 - 印尼
it
0x0010
義大利文
it-IT
0x0410
義大利文 - 義大利
it-CH
0x0810
義大利文 - 瑞士
ja
0x0011
日文
ja-JP
0x0411
日文 - 日本
kn
0x004B
坎那達文
kn-IN
0x044B
坎那達文 - 印度
kk
0x003F
哈薩克文
kk-KZ
0x043F
哈薩克文 - 哈薩克
kok
0x0057
貢根文
kok-IN
0x0457
貢根文 - 印度
ko
0x0012
韓文
ko-KR
0x0412
韓文 - 韓國
ky
0x0040
吉爾吉斯文
ky-KG
0x0440
吉爾吉斯文 - 吉爾吉斯
lv
0x0026
拉脫維亞文
lv-LV
0x0426
拉脫維亞文 - 拉脫維亞
lt
0x0027
立陶宛文
lt-LT
0x0427
立陶宛文 - 立陶宛
mk
0x002F
馬其頓文
mk-MK
0x042F
馬其頓文 - 馬其頓共和國
ms
0x003E
馬來文
ms-BN
0x083E
馬來文 - 汶萊
ms-MY
0x043E
馬來文 - 馬來西亞
mr
0x004E
馬拉提文
mr-IN
0x044E
馬拉提文 - 印度
mn
0x0050
蒙古文
mn-MN
0x0450
蒙古文 - 蒙古

0x0014
挪威文
nb-NO
0x0414
挪威文 (巴克摩) - 挪威
nn-NO
0x0814
挪威文 (耐諾斯克) - 挪威
pl
0x0015
波蘭文
pl-PL
0x0415
波蘭文 - 波蘭
pt
0x0016
葡萄牙文
pt-BR
0x0416
葡萄牙文 - 巴西
pt-PT
0x0816
葡萄牙文 - 葡萄牙
pa
0x0046
旁遮普語
pa-IN
0x0446
旁遮普語 - 印度
ro
0x0018
羅馬尼亞文
ro-RO
0x0418
羅馬尼亞文 - 羅馬尼亞
ru
0x0019
俄文
ru-RU
0x0419
俄文 - 俄羅斯
sa
0x004F
梵文
sa-IN
0x044F
梵文 - 印度
sr-SP-Cyrl
0x0C1A
塞爾維亞文 (斯拉夫) - 塞爾維亞
sr-SP-Latn
0x081A
塞爾維亞文 (拉丁) - 塞爾維亞
sk
0x001B
斯洛伐克文
sk-SK
0x041B
斯洛伐克文 - 斯洛伐克
sl
0x0024
斯洛維尼亞文
sl-SI
0x0424
斯洛維尼亞文 - 斯洛維尼亞
es
0x000A
西班牙文
es-AR
0x2C0A
西班牙文 - 阿根廷
es-BO
0x400A
西班牙文 - 玻利維亞
es-CL
0x340A
西班牙文 - 智利
es-CO
0x240A
西班牙文 - 哥倫比亞
es-CR
0x140A
西班牙文 - 哥斯大黎加
es-DO
0x1C0A
西班牙文 - 多明尼加
es-EC
0x300A
西班牙文 - 厄瓜多
es-SV
0x440A
西班牙文 - 薩爾瓦多
es-GT
0x100A
西班牙文 - 瓜地馬拉
es-HN
0x480A
西班牙文 - 宏都拉斯
es-MX
0x080A
西班牙文 - 墨西哥
es-NI
0x4C0A
西班牙文 - 尼加拉瓜
es-PA
0x180A
西班牙文 - 巴拿馬
es-PY
0x3C0A
西班牙文 - 巴拉圭
es-PE
0x280A
西班牙文 - 祕魯
es-PR
0x500A
西班牙文 - 波多黎各
es-ES
0x0C0A
西班牙文 - 西班牙
es-UY
0x380A
西班牙文 - 烏拉圭
es-VE
0x200A
西班牙文 - 委內瑞拉
sw
0x0041
史瓦西里文
sw-KE
0x0441
史瓦西里文 - 肯亞
sv
0x001D
瑞典文
sv-FI
0x081D
瑞典文 - 芬蘭
sv-SE
0x041D
瑞典文 - 瑞典
syr
0x005A
敘利亞文
syr-SY
0x045A
敘利亞文 - 敘利亞
ta
0x0049
坦米爾文
ta-IN
0x0449
坦米爾文 - 印度
tt
0x0044
韃靼文
tt-RU
0x0444
韃靼文 - 俄羅斯
te
0x004A
特拉古文
te-IN
0x044A
特拉古文 - 印度
th
0x001E
泰文
th-TH
0x041E
泰文 - 泰國
tr
0x001F
土耳其文
tr-TR
0x041F
土耳其文 - 土耳其
uk
0x0022
烏克蘭文
uk-UA
0x0422
烏克蘭文 - 烏克蘭
ur
0x0020
烏都文
ur-PK
0x0420
烏都文 - 巴基斯坦
uz
0x0043
烏茲別克文
uz-UZ-Cyrl
0x0843
烏茲別克文 (斯拉夫) - 烏茲別克
uz-UZ-Latn
0x0443
烏茲別克文 (拉丁) - 烏茲別克
vi
0x002A
越南文
vi-VN
0x042A
越南文 - 越南

http://msdn.microsoft.com/zh-tw/library/system.globalization.cultureinfo(v=vs.80).aspx#Y12636

2011年9月15日 星期四

vb.net 格式化日期成為書寫格式

轉載這篇
http://www.dotnetperls.com/datetime-format-vbnet

The DateTime type can be formatted with a string pattern in the VB.NET language. Conceptually, this is simple, but in practice there are some details you must account for if you want a functional program. As shown in this article, formatting your DateTime as a string is straightforward with an understanding of the syntax.

Example 1

As we begin, please notice how the current DateTime is acquired through the DateTime.Now property; when you execute these code examples, the current DateTime will be different. In this example, a format string beginning with MMM (for the month) is used. Look at how the pattern matches up to the output of the program.
Program that uses format string with DateTime [VB.NET]

Module Module1
Sub Main()
' Use current time.
' ... Use a format.
' ... Write to console.
Dim time As DateTime = DateTime.Now
Dim format As String = "MMM ddd d HH:mm yyyy"
Console.WriteLine(time.ToString(format))
End Sub
End Module

Output

May Tue 18 16:46 2010

Description of format

MMM Three-letter month.
ddd Three-letter day of the week.
d Day of the month.
HH Two-digit hours on 24-hour scale.
mm Two-digit minutes.
yyyy Four-digit year.
Example 2

It is possible to change the pattern used in the formatting string in many different ways. To explore this, we try to shorten the output by changing the MMM to a single M, along with several other similar changes. Again, notice how the pattern matches up to the output of the program. Further, the description of the formatting string is shown in tabular format.
Another program that uses format string [VB.NET]

Module Module1
Sub Main()
' Use current time.
' ... Use a format.
' ... Write to console.
Dim time As DateTime = DateTime.Now
Dim format As String = "M d HH:mm yy"
Console.WriteLine(time.ToString(format))
End Sub
End Module

Output

5 18 16:46 10

Description of format

M One-digit month number.
d One-digit day of the month.
HH Two-digit hours on 24-hour scale.
mm Two-digit minutes.
yy Two-digit year.
One-character format strings

Another feature of the DateTime formatting mechanism in VB.NET, which is accessible through the ToString function, is the single-character format string. For this feature, you pass a one-character string to the ToString function; this encodes a specific formatting style. Sometimes, it might be worth memorizing the ones you like the most, but in other cases you can simply look up the table on the Internet or MSDN.
Program that uses one-character formats [VB.NET]

Module Module1
Sub Main()
' Acquire current time and then try format strings.
Dim now As DateTime = DateTime.Now
Console.WriteLine(now.ToString("d"))
Console.WriteLine(now.ToString("D"))
Console.WriteLine(now.ToString("f"))
Console.WriteLine(now.ToString("F"))
Console.WriteLine(now.ToString("g"))
Console.WriteLine(now.ToString("G"))
Console.WriteLine(now.ToString("m"))
Console.WriteLine(now.ToString("M"))
Console.WriteLine(now.ToString("o"))
Console.WriteLine(now.ToString("O"))
Console.WriteLine(now.ToString("s"))
Console.WriteLine(now.ToString("t"))
Console.WriteLine(now.ToString("T"))
Console.WriteLine(now.ToString("u"))
Console.WriteLine(now.ToString("U"))
Console.WriteLine(now.ToString("y"))
Console.WriteLine(now.ToString("Y"))
End Sub
End Module

Output

5/18/2010
Tuesday, May 18, 2010
Tuesday, May 18, 2010 4:47 PM
Tuesday, May 18, 2010 4:47:55 PM
5/18/2010 4:47 PM
5/18/2010 4:47:55 PM
May 18
May 18
2010-05-18T16:47:55.9620000-06:00
2010-05-18T16:47:55.9620000-06:00
2010-05-18T16:47:55
4:47 PM
4:47:55 PM
2010-05-18 16:47:55Z
Tuesday, May 18, 2010 10:47:55 PM
May, 2010
May, 2010
Helper string functions

There are also several helper functions available on a DateTime instance that allow you to format a string in a specific way. For rapid application development, these are ideal because they are easy to remember and guess. Notice how the methods with the word Long in them produce considerably more verbose output.
Program that uses DateTime string functions [VB.NET]

Module Module1
Sub Main()
' Use string helper functions.
Dim now As DateTime = DateTime.Now
Console.WriteLine(now.ToLongDateString())
Console.WriteLine(now.ToLongTimeString())
Console.WriteLine(now.ToShortDateString())
Console.WriteLine(now.ToShortTimeString())
Console.WriteLine(now.ToString())
End Sub
End Module

Output

Tuesday, May 18, 2010
4:49:57 PM
5/18/2010
4:49 PM
5/18/2010 4:49:57 PM
Short day strings

The .NET Framework gives you the ability to print the representation of a day in short form. The three-letter form used simply takes a substring of the day in English and truncates it to three characters. In this example, we look at a loop construct that loops through seven days and prints out the short form string for each of them.
Program that prints short day strings [VB.NET]

Module Module1
Sub Main()
' Current time.
Dim now As DateTime = DateTime.Now

' Print out all the days.
For index As Integer = 0 To 6
Console.WriteLine(now.ToString("ddd"))
now = now.AddDays(1)
Next
End Sub
End Module

Output

Tue
Wed
Thu
Fri
Sat
Sun
Mon
Long day strings

You can also print out the long day strings using the format string dddd. For more textually-oriented output, the longer day string might seem more professional and authoritative. In this example, we loop over seven consecutive days and print out the long day strings.
Program that prints long day strings [VB.NET]

Module Module1
Sub Main()
Dim now As DateTime = DateTime.Now
For index As Integer = 0 To 6
Console.WriteLine(now.ToString("dddd"))
now = now.AddDays(1)
Next
End Sub
End Module

Output

Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
Monday
AM and PM strings

When you are using a 12-hour based time system, you will typically want to display AM or PM to indicate whether it is morning or evening. This example prints out AM and PM for two times that are twelve hours apart, demonstrating the syntax and correctness of this format string.
Program that prints AM and PM [VB.NET]

Module Module1
Sub Main()
Dim now As DateTime = DateTime.Now
For index As Integer = 0 To 1
Console.WriteLine(now.ToString("tt "))
now = now.AddHours(12)
Next
End Sub
End Module

Output

PM
AM
Year strings

The year part of the format string is also very important. Typically, you will want a two or four digit year, but a one-digit year is also possible with a single y. To exemplify this format character, we look at some output in an example program that tests yy and yyyy.
Program that prints year strings [VB.NET]

Module Module1
Sub Main()
' Use the best y patterns.
Dim now As DateTime = DateTime.Now
Console.WriteLine(now.ToString("yy"))
Console.WriteLine(now.ToString("yyyy"))
End Sub
End Module

Output

10
2010

2011年9月13日 星期二

Oracle 時間日期

轉載這篇文章

http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html




Resources
Database Systems: The Complete Book by Hector Garcia, Jeff Ullman, and Jennifer Widom.

A First Course in Database Systems by Jeff Ullman and Jennifer Widom.

Gradiance SQL Tutorial.
Oracle Dates and Times
--------------------------------------------------------------------------------

Overview
DATE Format
The Current Time
Operations on DATE
Further Information

--------------------------------------------------------------------------------
Overview
Oracle supports both date and time, albeit differently from the SQL2 standard. Rather than using two separate entities, date and time, Oracle only uses one, DATE. The DATE type is stored in a special internal format that includes not just the month, day, and year, but also
the hour, minute, and second.
The DATE type is used in the same way as other built-in types such as INT. For example, the following SQL statement creates a relation with an attribute of type DATE:

create table x(a int, b date);

--------------------------------------------------------------------------------
DATE Format
When a DATE value is displayed, Oracle must first convert that value from the special internal format to a printable string. The conversion is done by a function TO_CHAR, according to a DATE format. Oracle's default format for DATE is "DD-MON-YY". Therefore, when you issue the query
select b from x;
you will see something like:
B
---------
01-APR-98
Whenever a DATE value is displayed, Oracle will call TO_CHAR automatically with the default DATE format. However, you may override the default behavior by calling TO_CHAR explicitly with your own DATE format. For example,
SELECT TO_CHAR(b, 'YYYY/MM/DD') AS b
FROM x;
returns the result:
B
---------------------------------------------------------------------------
1998/04/01
The general usage of TO_CHAR is:
TO_CHAR(, '')
where the string can be formed from over 40 options. Some of the more popular ones include:
MM Numeric month (e.g., 07)
MON Abbreviated month name (e.g., JUL)
MONTH Full month name (e.g., JULY)
DD Day of month (e.g., 24)
DY Abbreviated name of day (e.g., FRI)
YYYY 4-digit year (e.g., 1998)
YY Last 2 digits of the year (e.g., 98)
RR Like YY, but the two digits are ``rounded'' to a year in the range 1950 to 2049. Thus, 06 is considered 2006 instead of 1906 , for example.
AM (or PM) Meridian indicator
HH Hour of day (1-12)
HH24 Hour of day (0-23)
MI Minute (0-59)
SS Second (0-59)

You have just learned how to output a DATE value using TO_CHAR. Now what about inputting a DATE value? This is done through a function called TO_DATE, which converts a string to a DATE value, again according to the DATE format. Normally, you do not have to call TO_DATE explicitly: Whenever Oracle expects a DATE value, it will automatically convert your input string using TO_DATE according to the default DATE format "DD-MON-YY". For example, to insert a tuple with a DATE attribute, you can simply type:

insert into x values(99, '31-may-98');
Alternatively, you may use TO_DATE explicitly:
insert into x
values(99, to_date('1998/05/31:12:00:00AM', 'yyyy/mm/dd:hh:mi:ssam'));
The general usage of TO_DATE is:
TO_DATE(, '')
where the string has the same options as in TO_CHAR.
Finally, you can change the default DATE format of Oracle from "DD-MON-YY" to something you like by issuing the following command in sqlplus:

alter session set NLS_DATE_FORMAT='';
The change is only valid for the current sqlplus session.

--------------------------------------------------------------------------------
The Current Time
The built-in function SYSDATE returns a DATE value containing the current date and time on your system. For example,
select to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI:SS') as "Current Time"
from dual;
returns
Current Time
---------------------------------------------------------------------------
Tue 21-Apr-1998 21:18:27
which is the time when I was preparing this document :-) Two interesting things to note here:
You can use double quotes to make names case sensitive (by default, SQL is case insensitive), or to force spaces into names. Oracle will treat everything inside the double quotes literally as a single name. In this example, if "Current Time" is not quoted, it would have been interpreted as two case insensitive names CURRENT and TIME, which would actually cause a syntax error.
DUAL is built-in relation in Oracle which serves as a dummy relation to put in the FROM clause when nothing else is appropriate. For example, try "select 1+2 from dual;".
Another name for the built-in function SYSDATE is CURRENT_DATE. Be aware of these special names to avoid name conflicts.

--------------------------------------------------------------------------------
Operations on DATE
You can compare DATE values using the standard comparison operators such as =, !=, >, etc.
You can subtract two DATE values, and the result is a FLOAT which is the number of days between the two DATE values. In general, the result may contain a fraction because DATE also has a time component. For obvious reasons, adding, multiplying, and dividing two DATE values are not allowed.

You can add and subtract constants to and from a DATE value, and these numbers will be interpreted as numbers of days. For example, SYSDATE+1 will be tomorrow. You cannot multiply or divide DATE values.

With the help of TO_CHAR, string operations can be used on DATE values as well. For example, to_char(, 'DD-MON-YY') like '%JUN%' evaluates to true if is in June.


--------------------------------------------------------------------------------
This document was written originally by Kristian Widjaja for Prof. Jeff Ullman's CS145 class in Autumn, 1997; revised by Jun Yang for Prof. Jennifer Widom's CS145 class in Spring, 1998; further revisions by Prof. Ullman in Autumn, 1998.

Vb.net 連線至Oracle 連線字串

真是太笨了,這種問題可以困擾很久....


"<" add name="Oracle" connectionstring="Server=xxx.xxx.xxx.xxx:1521/資料庫名稱;User ID=使用者名稱;Password=使用者密碼;Persist Security Info=True" name="Oracle" "> " "<"/add ">"

2011年9月9日 星期五

jsp 呼叫 .Net 所寫的 WebService

這裡需要先當露 jsp 所需要的元件 Axis ,目前本人的環境為 Axis1.4版+Apache Tomcat 6.0+Java 7(?)

下載完後,解壓縮資料夾,把 webapps\axis\WEB-INF\lib 目錄下的所有檔案,複製到 TomCat的 webapps\ROOT\WEB-INF\lib 裡面,同樣的,把 webapps\axis\WEB-INF\classes 複製到TomCat的webapps\ROOT\WEB-INF\classes裡面

編輯環境變數


新增
名稱:AXIS_HOME            值:%TOMCAT_HOME%\webapps\axis
名稱:AXIS_LIB                 值:%AXIS_HOME%\lib
名稱:AXISCLASSPATH  值:%AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discovery.jar; %AXIS_LIB%\commons-logging.jar;%AXIS_LIB%\jaxrpc.jar; %AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j-1.2.8.jar; %AXIS_LIB%\xml-apis.jar;%AXIS_LIB%\xercesImpl.jar

嗯。。。。。有點麻煩吧。。。

接下來,把剛剛解壓縮的 Axis目錄打開,把webapps目錄下的axis目錄,整個複製到
TomCat的 webapps 下,在瀏覽器上打

http://自己湯姆貓的網址/axis ,會出現測試網頁


接下來,都沒問題的話,在瀏覽器上打
http://自己湯姆貓的網址/axis/happyaxis.jsp ,會出現測試的結果


沒什麼大問題的話,就可以開始享受寫Code的樂趣了

以下是.net的WebService

VB.net:

    _
    Public Function TestHello(ByVal strName As String) As String
        Try
            My.Computer.FileSystem.WriteAllText("D:\tmp\test.txt", strName & vbCrLf, True)
        Catch ex As Exception

        End Try
        Return "Hello" & strName
    End Function
End Class


我們這次的測試目標擺在最後一個 Function (TestHello),測試方式很簡單,我傳進一個名稱,回傳 『Hello』+ 『傳入名稱』,例如傳入『 Randy笨蛋』,會回傳 『Hello Randy笨蛋』

接下來是JSP的 code

JSP:

需要傳入的套件
org.apache.axis.client.Call
org.apache.axis.client.Service
javax.xml.namespace.QName
java.util.Date
java.text.DateFormat
java.lang.Integer
javax.xml.rpc.ParameterMode

主要的code:

String strEndpoint = "http://localhost/TestWS/service1.asmx";
//注意,這個NameSpace一定要設定,不然傳進的參數永遠都NULL
String strNameSpace="http://localhost/TestWS/";

Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(strEndpoint));
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://localhost/TestWS/TestHello");
call.setOperationName(new QName(strNameSpace,"TestHello"));
call.addParameter(new QName(strNameSpace,"strName"), org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
String result;
call.setTargetEndpointAddress(new java.net.URL(strEndpoint));
result=(String) call.invoke(new Object[] {" Randy笨蛋"});


=result


請注意

String strNameSpace="http://localhost/TestWS/";
call.setOperationName(new QName(strNameSpace,"TestHello"));
call.addParameter(new QName(strNameSpace,"strName"), org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN); 

傳錯了,所有String 的參數都是NULL,所有Integer的參數都是0,意思是萬劫不復,永不超生的地獄就此展開,永遠的一路靠北--邊走。。。Debug到天荒地老也是沒結果,就跟把正妹一樣,而且這裡的錯誤是沒錯誤訊息....就如同被女生拒絕也不知道,被發好人卡卻又可以約出去玩,超級大大大好人,別再犯這個錯,親愛的網友們,注意這個微不足道的小重點吧。。


所以我們期望的結果是『Hello Randy笨蛋』

以下就是執行結果



出現的是『Hello Randy�³J 』,沒錯,編碼問題,編碼問題本人有時間在試試 @@...