iT邦幫忙

0

[VS] C# web service 新增&使用

OS : W7
開發平台:VS 2013
framework版本:Microsoft.NET Framework 4.0
IIS : IIS 7

怎麼做一個web service

1.新增專案(webservice)
2.建立服務(WebService1)
加入/新增項目/web 服務(ASMX)
https://ithelp.ithome.com.tw/upload/images/20190618/20106764ebLGrhTBke.png
https://ithelp.ithome.com.tw/upload/images/20190618/20106764Tyv5XPsLHp.png

3.瀏覽網頁 - 檢查看看有沒有什麼問題
按F5瀏覽網頁
https://ithelp.ithome.com.tw/upload/images/20190618/20106764FK9gVp0Zm9.png
WebService,提供一個funtion HellowWorld
https://ithelp.ithome.com.tw/upload/images/20190618/20106764BHyXC2Lzvx.png
https://ithelp.ithome.com.tw/upload/images/20190618/20106764DcTvnST3nB.pnghttps://ithelp.ithome.com.tw/upload/images/20190618/201067643A7SZCPi4B.pnghttps://ithelp.ithome.com.tw/upload/images/20190618/20106764MmKHF6tsMG.png

4.架設到IIS

怎麼架設webservice?

跟架網站一樣,到IIS上架
http://192.168.xx.xx:77/WebService1.asmx

  1. 新增網站
    https://ithelp.ithome.com.tw/upload/images/20190618/20106764ilHK4pDl7v.png
    https://ithelp.ithome.com.tw/upload/images/20190618/201067643zszIg4qoB.png
  2. 確認應用程式集區與web.config相符
    https://ithelp.ithome.com.tw/upload/images/20190618/201067647qB0UQbRRx.png

怎麼使用webservice

1.新增專案callwebservice
2.加入web參考
http://192.168.xx.xx:77/WebService1.asmx 命名為WebReference
https://ithelp.ithome.com.tw/upload/images/20190618/20106764UfSQZTSHnJ.pnghttps://ithelp.ithome.com.tw/upload/images/20190618/201067647dJeCZstho.pnghttps://ithelp.ithome.com.tw/upload/images/20190618/20106764I2le77Fbe1.pnghttps://ithelp.ithome.com.tw/upload/images/20190618/20106764IQ7d49Quhl.pnghttps://ithelp.ithome.com.tw/upload/images/20190618/20106764qeLAsWdXBY.png
這樣就完成了,我們可以看到以下2個地方都有了變化.
1.多了一個Web References
https://ithelp.ithome.com.tw/upload/images/20190618/20106764JcNYiuirMo.png
2. Propeties 多了Settings.settings
點Settings.settings可以看到Web.cofig 增加了 applicationSettings區段
https://ithelp.ithome.com.tw/upload/images/20190618/201067647tm7fvmZvh.png
3.新增WebForm頁面 (建立service & 呼叫)
callwebservice.WebReference.WebService1 wf = new WebReference.WebService1();
Response.Write("alert('" + wf.HelloWorld() + "');");
https://ithelp.ithome.com.tw/upload/images/20190618/20106764lIjzCD4hL6.png

其它-查看webservice有什麼function

https://ithelp.ithome.com.tw/upload/images/20190618/201067641QiIfjoJEM.png
https://ithelp.ithome.com.tw/upload/images/20190618/20106764jzI6tir1N5.png

QA webservice壞去啊

因為內底有一咧function有問題
將依拿掉就好啊

QA Chrome 错误代码:ERR_UNSAFE_PORT

https://ithelp.ithome.com.tw/upload/images/20190618/20106764dHNtbchZCR.png
解決方法,把PORT,改成777,就好了
http://blog.csdn.net/testcs_dn/article/details/39186225

建议尽量避免以下端口:
1, // tcpmux
7, // echo
9, // discard
11, // systat
13, // daytime
15, // netstat
17, // qotd
19, // chargen
20, // ftp data
21, // ftp access
22, // ssh
23, // telnet
25, // smtp
37, // time
42, // name
43, // nicname
53, // domain
77, // priv-rjs
79, // finger
87, // ttylink
95, // supdup
101, // hostriame
102, // iso-tsap
103, // gppitnp
104, // acr-nema
109, // pop2
110, // pop3
111, // sunrpc
113, // auth
115, // sftp
117, // uucp-path
119, // nntp
123, // NTP
135, // loc-srv /epmap
139, // netbios
143, // imap2
179, // BGP
389, // ldap
465, // smtp+ssl
512, // print / exec
513, // login
514, // shell
515, // printer
526, // tempo
530, // courier
531, // chat
532, // netnews
540, // uucp
556, // remotefs
563, // nntp+ssl
587, // stmp?
601, // ??
636, // ldap+ssl
993, // ldap+ssl
995, // pop3+ssl
2049, // nfs
3659, // apple-sasl / PasswordServer
4045, // lockd
6000, // X11
6665, // Alternate IRC [Apple addition]
6666, // Alternate IRC [Apple addition]
6667, // Standard IRC [Apple addition]
6668, // Alternate IRC [Apple addition]
6669, // Alternate IRC [Apple addition]


尚未有邦友留言

立即登入留言