php如何調(diào)用webservice應(yīng)用介紹
Jun 13, 2016 am 11:56 AM
1.1、Web Service基本概念
Web Service也叫XML Web Service WebService是一種可以接收從Internet或者Intranet上的其它系統(tǒng)中傳遞過(guò)來(lái)的請(qǐng)求,輕量級(jí)的獨(dú)立的通訊技術(shù)。是:通過(guò)SOAP在Web上提供的軟件服務(wù),使用WSDL文件進(jìn)行說(shuō)明,并通過(guò)UDDI進(jìn)行注冊(cè)。
XML:(Extensible Markup Language)擴(kuò)展型可標(biāo)記語(yǔ)言。面向短期的臨時(shí)數(shù)據(jù)處理、面向萬(wàn)維網(wǎng)絡(luò),是Soap的基礎(chǔ)。
Soap:(Simple Object Access Protocol)簡(jiǎn)單對(duì)象存取協(xié)議。是XML Web Service 的通信協(xié)議。當(dāng)用戶通過(guò)UDDI找到你的WSDL描述文檔后,他通過(guò)可以SOAP調(diào)用你建立的Web服務(wù)中的一個(gè)或多個(gè)操作。SOAP是XML文檔形式的調(diào)用方法的規(guī)范,它可以支持不同的底層接口,像HTTP(S)或者SMTP。
WSDL:(Web Services Description Language) WSDL 文件是一個(gè) XML 文檔,用于說(shuō)明一組 SOAP 消息以及如何交換這些消息。大多數(shù)情況下由軟件自動(dòng)生成和使用。
UDDI (Universal Description, Discovery, and Integration) 是一個(gè)主要針對(duì)Web服務(wù)供應(yīng)商和使用者的新項(xiàng)目。在用戶能夠調(diào)用Web服務(wù)之前,必須確定這個(gè)服務(wù)內(nèi)包含哪些商務(wù)方法,找到被調(diào)用的接口定義,還要在服務(wù)端來(lái)編制軟件,UDDI是一種根據(jù)描述文檔來(lái)引導(dǎo)系統(tǒng)查找相應(yīng)服務(wù)的機(jī)制。UDDI利用SOAP消息機(jī)制(標(biāo)準(zhǔn)的XML/HTTP)來(lái)發(fā)布,編輯,瀏覽以及查找注冊(cè)信息。它采用XML格式來(lái)封裝各種不同類型的數(shù)據(jù),并且發(fā)送到注冊(cè)中心或者由注冊(cè)中心來(lái)返回需要的數(shù)據(jù)。
1.2、XML Web Service的特點(diǎn)
Web Service的主要目標(biāo)是跨平臺(tái)的可互操作性。為了實(shí)現(xiàn)這一目標(biāo),Web Service 完全基于XML(可擴(kuò)展標(biāo)記語(yǔ)言)、XSD(XML Schema)等獨(dú)立于平臺(tái)、獨(dú)立于軟件供應(yīng)商的標(biāo)準(zhǔn),是創(chuàng)建可互操作的、分布式應(yīng)用程序的新平臺(tái)。因此使用Web Service有許多優(yōu)點(diǎn):
1、跨防火墻的通信
如果應(yīng)用程序有成千上萬(wàn)的用戶,而且分布在世界各地,那么客戶端和服務(wù)器之間的通信將是一個(gè)棘手的問(wèn)題。因?yàn)榭蛻舳撕头?wù)器之間通常會(huì)有防火墻或者代理服務(wù)器。傳統(tǒng)的做法是,選擇用瀏覽器作為客戶端,寫(xiě)下一大堆ASP頁(yè)面,把應(yīng)用程序的中間層暴露給最終用戶。這樣做的結(jié)果是開(kāi)發(fā)難度大,程序很難維護(hù)。 要是客戶端代碼不再如此依賴于HTML表單,客戶端的編程就簡(jiǎn)單多了。如果中間層組件換成Web Service的話,就可以從用戶界面直接調(diào)用中間層組件,從而省掉建立ASP頁(yè)面的那一步。要調(diào)用Web Service,可以直接使用Microsoft SOAP Toolkit或.net這樣的SOAP客戶端,也可以使用自己開(kāi)發(fā)的SOAP客戶端,然后把它和應(yīng)用程序連接起來(lái)。不僅縮短了開(kāi)發(fā)周期,還減少了代碼復(fù)雜度,并能夠增強(qiáng)應(yīng)用程序的可維護(hù)性。同時(shí),應(yīng)用程序也不再需要在每次調(diào)用中間層組件時(shí),都跳轉(zhuǎn)到相應(yīng)的"結(jié)果頁(yè)"。
2、應(yīng)用程序集成
企業(yè)級(jí)的應(yīng)用程序開(kāi)發(fā)者都知道,企業(yè)里經(jīng)常都要把用不同語(yǔ)言寫(xiě)成的、在不同平臺(tái)上運(yùn)行的各種程序集成起來(lái),而這種集成將花費(fèi)很大的開(kāi)發(fā)力量。應(yīng)用程序經(jīng)常需要從運(yùn)行的一臺(tái)主機(jī)上的程序中獲取數(shù)據(jù);或者把數(shù)據(jù)發(fā)送到主機(jī)或其它平臺(tái)應(yīng)用程序中去。即使在同一個(gè)平臺(tái)上,不同軟件廠商生產(chǎn)的各種軟件也常常需要集成起來(lái)。通過(guò)Web Service,應(yīng)用程序可以用標(biāo)準(zhǔn)的方法把功能和數(shù)據(jù)"暴露"出來(lái),供其它應(yīng)用程序使用。
XML Web services 提供了在松耦合環(huán)境中使用標(biāo)準(zhǔn)協(xié)議(HTTP、XML、SOAP 和 WSDL)交換消息的能力。消息可以是結(jié)構(gòu)化的、帶類型的,也可以是松散定義的。
3、B2B的集成
B2B 指的是Business to Business,as in businesses doing business with other businesses,商家(泛指企業(yè))對(duì)商家的電子商務(wù),即企業(yè)與企業(yè)之間通過(guò)互聯(lián)網(wǎng)進(jìn)行產(chǎn)品、服務(wù)及信息的交換。通俗的說(shuō)法是指進(jìn)行電子商務(wù)交易的供需雙方都是商家(或企業(yè)、公司),她們使用了Internet的技術(shù)或各種商務(wù)網(wǎng)絡(luò)平臺(tái),完成商務(wù)交易的過(guò)程。
Web Service是B2B集成成功的關(guān)鍵。通過(guò)Web Service,公司可以只需把關(guān)鍵的商務(wù)應(yīng)用"暴露"給指定的供應(yīng)商和客戶,就可以了,Web Service運(yùn)行在Internet上,在世界任何地方都可輕易實(shí)現(xiàn),其運(yùn)行成本就相對(duì)較低。Web Service只是B2B集成的一個(gè)關(guān)鍵部分,還需要許多其它的部分才能實(shí)現(xiàn)集成。 用Web Service來(lái)實(shí)現(xiàn)B2B集成的最大好處在于可以輕易實(shí)現(xiàn)互操作性。只要把商務(wù)邏輯"暴露"出來(lái),成為Web Service,就可以讓任何指定的合作伙伴調(diào)用這些商務(wù)邏輯,而不管他們的系統(tǒng)在什么平臺(tái)上運(yùn)行,使用什么開(kāi)發(fā)語(yǔ)言。這樣就大大減少了花在B2B集成上的時(shí)間和成本。
4、軟件和數(shù)據(jù)重用
Web Service在允許重用代碼的同時(shí),可以重用代碼背后的數(shù)據(jù)。使用Web Service,再也不必像以前那樣,要先從第三方購(gòu)買(mǎi)、安裝軟件組件,再?gòu)膽?yīng)用程序中調(diào)用這些組件;只需要直接調(diào)用遠(yuǎn)端的Web Service就可以了。另一種軟件重用的情況是,把好幾個(gè)應(yīng)用程序的功能集成起來(lái),通過(guò)Web Service "暴露"出來(lái),就可以非常容易地把所有這些功能都集成到你的門(mén)戶站點(diǎn)中,為用戶提供一個(gè)統(tǒng)一的、友好的界面。 可以在應(yīng)用程序中使用第三方的Web Service 提供的功能,也可以把自己的應(yīng)用程序功能通過(guò)Web Service 提供給別人。兩種情況下,都可以重用代碼和代碼背后的數(shù)據(jù)。
從以上論述可以看出,Web Service 在通過(guò)Web進(jìn)行互操作或遠(yuǎn)程調(diào)用的時(shí)候是最有用的。不過(guò),也有一些情況,Web Service根本不能帶來(lái)任何好處,Web Service有一下缺點(diǎn):
1、單機(jī)應(yīng)用程序
目前,企業(yè)和個(gè)人還使用著很多桌面應(yīng)用程序。其中一些只需要與本機(jī)上的其它程序通信。在這種情況下,最好就不要用Web Service,只要用本地的API就可以了。COM非常適合于在這種情況下工作,因?yàn)樗刃∮挚?。運(yùn)行在同一臺(tái)服務(wù)器上的服務(wù)器軟件也是這樣。當(dāng)然Web Service 也能用在這些場(chǎng)合,但那樣不僅消耗太大,而且不會(huì)帶來(lái)任何好處。
2、局域網(wǎng)的一些應(yīng)用程序
在許多應(yīng)用中,所有的程序都是在Windows平臺(tái)下使用COM,都運(yùn)行在同一個(gè)局域網(wǎng)上。在這些程序里,使用DCOM會(huì)比SOAP/HTTP有效得多。與此相類似,如果一個(gè).net程序要連接到局域網(wǎng)上的另一個(gè).net程序,應(yīng)該使用.net Remoting。其實(shí)在.net Remoting中,也可以指定使用SOAP/HTTP來(lái)進(jìn)行Web Service 調(diào)用。不過(guò)最好還是直接通過(guò)TCP進(jìn)行RPC調(diào)用,那樣會(huì)有效得多。
1.3、XML Web Service的應(yīng)用
1.最初的 XML Web Service 通常是可以方便地并入應(yīng)用程序的信息來(lái)源,如股票價(jià)格、天氣預(yù)報(bào)、體育成績(jī)等等。
2.以 XML Web Service 方式提供現(xiàn)有應(yīng)用程序,可以構(gòu)建新的、更強(qiáng)大的應(yīng)用程序,并利用 XML Web Service 作為構(gòu)造塊。
例如,用戶可以開(kāi)發(fā)一個(gè)采購(gòu)應(yīng)用程序,以自動(dòng)獲取來(lái)自不同供應(yīng)商的價(jià)格信息,從而使用戶可以選擇供應(yīng)商,提交訂單,然后跟蹤貨物的運(yùn)輸,直至收到貨物。而供應(yīng)商的應(yīng)用程序除了在Web上提供服務(wù)外,還可以使用XML Web Service檢查客戶的信用、收取貨款,并與貨運(yùn)公司辦理貨運(yùn)手續(xù)。
二、Web Service開(kāi)發(fā)
.net平臺(tái)內(nèi)建了對(duì)Web Service的支持,包括Web Service的構(gòu)建和使用。與其它開(kāi)發(fā)平臺(tái)不同,使用.net平臺(tái),你不需要其他的工具或者SDK就可以完成Web Service的開(kāi)發(fā)了。.net Framework本身就全面支持Web Service,包括服務(wù)器端的請(qǐng)求處理器和對(duì)客戶端發(fā)送和接受SOAP消息的支持。下來(lái)我們就一步一步的用Microsoft Visual Studio .net 20058(后面簡(jiǎn)稱VS.Net 2008)創(chuàng)建和使用一個(gè)簡(jiǎn)單的Web Service。
2.1、用創(chuàng)建一個(gè)最簡(jiǎn)單的Web Service
首先,打開(kāi)VS2005,打開(kāi)"文件-新建-網(wǎng)站",選擇"ASP.NET Web服務(wù)"
?
查看Service.cs代碼,你會(huì)發(fā)現(xiàn)VS.Net 2005已經(jīng)為Web Service文件建立了缺省的框架。原始代碼為:
復(fù)制代碼 代碼如下:
using System;??
using System.Linq;??
using System.Web;??
using System.Web.Services;??
using System.Web.Services.Protocols;??
using System.Xml.Linq;??
[WebService(Namespace = "http://tempuri.org/")]??
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]??
// 若要允許使用 ASP.NET AJAX 從腳本中調(diào)用此 Web 服務(wù),請(qǐng)取消對(duì)下行的注釋。??
// [System.Web.Script.Services.ScriptService]??
public class Service : System.Web.Services.WebService??
{??
??? public Service () {??
??????? //如果使用設(shè)計(jì)的組件,請(qǐng)取消注釋以下行???
??????? //InitializeComponent();???
??? }??
??? [WebMethod]??
??? public string HelloWorld()??
??? {??
??????? return "Hello World";??
??? }??
}?
using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允許使用 ASP.NET AJAX 從腳本中調(diào)用此 Web 服務(wù),請(qǐng)取消對(duì)下行的注釋。
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
??? public Service () {
??????? //如果使用設(shè)計(jì)的組件,請(qǐng)取消注釋以下行
??????? //InitializeComponent();
??? }
??? [WebMethod]
??? public string HelloWorld()
??? {
??????? return "Hello World";
??? }
}
默認(rèn)工程里面已經(jīng)有一個(gè)Hello World的方法了,直接運(yùn)行看看效果,
?
點(diǎn)擊顯示頁(yè)面上圖中的"HelloWorld"超鏈接,跳轉(zhuǎn)到下一頁(yè)面:
?
點(diǎn)擊"調(diào)用"按鈕,就可以看到用XML格式返回的Web Service結(jié)果下圖。說(shuō)明我們的Web Service環(huán)境沒(méi)有問(wèn)題,而且還初步接觸了一下最簡(jiǎn)單的Web Service。
2.2、創(chuàng)建一個(gè)簡(jiǎn)單帶有功能的Web Service
上面我們宏觀的了解了webservice,其實(shí)它就是個(gè)對(duì)外的接口,里面有函數(shù)可供外部客戶調(diào)用(注意:里面同樣有客戶不可調(diào)用的函數(shù)).假若我們是服務(wù)端,我們寫(xiě)好了個(gè)webservice,然后把它給了客戶(同時(shí)我們給了他們調(diào)用規(guī)則),客戶就可以在從服務(wù)端獲取信息時(shí)處于一個(gè)相對(duì)透明的狀態(tài).即是客戶不了解(也不需要)其過(guò)程,他們只獲取數(shù)據(jù).在代碼文件里,如果我們寫(xiě)了一個(gè)函數(shù)后,希望此函數(shù)成為外部可調(diào)用的接口函數(shù),我們必須在函數(shù)上面添上一行代碼[WebMethod(Description="函數(shù)的描述信息")],如果你的函數(shù)沒(méi)有這個(gè)申明,它將不能被用戶引用.下來(lái)我們開(kāi)始編寫(xiě)一個(gè)簡(jiǎn)單的Web Service 的例子。
先把默認(rèn)的HelloWorld方法注釋掉,簡(jiǎn)單的寫(xiě)了求加減乘除運(yùn)算的四個(gè)方法;
復(fù)制代碼 代碼如下:
using System;??
using System.Linq;??
using System.Web;??
using System.Web.Services;??
using System.Web.Services.Protocols;??
using System.Xml.Linq;??
[WebService(Namespace = "http://tempuri.org/")]??
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]??
// 若要允許使用 ASP.NET AJAX 從腳本中調(diào)用此 Web 服務(wù),請(qǐng)取消對(duì)下行的注釋。??
// [System.Web.Script.Services.ScriptService]??
public class Service : System.Web.Services.WebService??
{??
??? public Service () {??
??????? //如果使用設(shè)計(jì)的組件,請(qǐng)取消注釋以下行???
??????? //InitializeComponent();???
??? }??
??? //[WebMethod]??
??? //public string HelloWorld()??
??? //{??
??? //??? return "Hello World";??
??? //}??
??? [WebMethod(Description = "求和的方法")]??
??? public double addition(double i, double j)??
??? {??
??????? return i + j;??
??? }??
??? [WebMethod(Description = "求差的方法")]??
??? public double subtract(double i, double j)??
??? {??
??????? return i - j;??
??? }??
??? [WebMethod(Description = "求積的方法")]??
??? public double multiplication(double i, double j)??
??? {??
??????? return i * j;??
??? }??
??? [WebMethod(Description = "求商的方法")]??
??? public double division(double i, double j)??
??? {??
??????? if (j != 0)??
??????????? return i / j;??
??????? else?
??????????? return 0;??
??? }??
}
復(fù)制代碼 代碼如下:
using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允許使用 ASP.NET AJAX 從腳本中調(diào)用此 Web 服務(wù),請(qǐng)取消對(duì)下行的注釋。
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
??? public Service () {
??????? //如果使用設(shè)計(jì)的組件,請(qǐng)取消注釋以下行
??????? //InitializeComponent();
??? }
??? //[WebMethod]
??? //public string HelloWorld()
??? //{
??? //??? return "Hello World";
??? //}
??? [WebMethod(Description = "求和的方法")]
??? public double addition(double i, double j)
??? {
??????? return i + j;
??? }
??? [WebMethod(Description = "求差的方法")]
??? public double subtract(double i, double j)
??? {
??????? return i - j;
??? }
??? [WebMethod(Description = "求積的方法")]
??? public double multiplication(double i, double j)
??? {
??????? return i * j;
??? }
??? [WebMethod(Description = "求商的方法")]
??? public double division(double i, double j)
??? {
??????? if (j != 0)
??????????? return i / j;
??????? else
??????????? return 0;
??? }
}
?
運(yùn)行可以看到我們自己寫(xiě)的可以被調(diào)用的方法,如下圖:
?
同樣點(diǎn)擊addition方法,進(jìn)入addition方法的調(diào)用頁(yè)。
?
在參數(shù)上面輸入?yún)?shù)i=3,j=3,如上圖,點(diǎn)擊調(diào)用,就可以看到用XML格式返回的Web Service結(jié)果(i與j相加的結(jié)果)下圖
到這里,我們會(huì)發(fā)現(xiàn),其實(shí)webservice并不是那么的神秘,它也不過(guò)只是個(gè)接口,對(duì)我們而言,側(cè)重點(diǎn)就是是接口函數(shù)的編寫(xiě).
2.3、用ASP.NET調(diào)用Web Service
首先,打開(kāi)VS2005,打開(kāi)"文件-新建-網(wǎng)站",選擇"ASP.NET網(wǎng)站"。
?
選好存儲(chǔ)位置,語(yǔ)言后點(diǎn)擊確定,進(jìn)入默認(rèn)頁(yè)面。然后先添加Web引用,把WebService引到當(dāng)前的工程里面。方法是:在資源管理器中點(diǎn)擊右鍵,選擇添加Web 引用,調(diào)出對(duì)話框:
?
在URL中填入,前面寫(xiě)好的WebService運(yùn)行后瀏覽器上面顯示的地址(即:WebService發(fā)布后的訪問(wèn)地址 ),點(diǎn)擊"前往"按鈕,如上圖,就會(huì)顯示出所引用的WebService中可以調(diào)用的方法,然后點(diǎn)擊"添加引用",就將webservice引用到了當(dāng)前的工程里面 ,如下圖,解決方案中會(huì)出現(xiàn)引進(jìn)來(lái)的WebService文件
?
我們?cè)谶@就練習(xí)調(diào)用webservice的四個(gè)方法,做一個(gè)簡(jiǎn)單的調(diào)用的例子,先在網(wǎng)站的前臺(tái)添加幾個(gè)控件,代碼如下:
復(fù)制代碼 代碼如下:
??
??
??
???
??
??
???
???
???????
???????????? ??
????????????
??????? ??
????????????
???
???
??
?
???
???
???
???????
????????????
????????????
???????
????????????
???
???
?
然后在后臺(tái)寫(xiě)調(diào)用的代碼,調(diào)用之前和使用其它的對(duì)象一樣,要先實(shí)例化,實(shí)例化的方法是localhost.Service a = new localhost.Service();然后就可以通過(guò)a來(lái)訪問(wèn)WebService里面提供的方法了。在這個(gè)例子里面,動(dòng)態(tài)的創(chuàng)建了一個(gè)button控件來(lái)觸發(fā)WebService的調(diào)用,后臺(tái)代碼如下:
運(yùn)行后可以看到效果,如下圖所示,在前面兩個(gè)Textbox里面輸入兩個(gè)操作數(shù),在中間的下拉列表中選擇操作符,然后點(diǎn)擊"="號(hào),將計(jì)算的結(jié)果輸出到第三個(gè)Textbox里面。
?
而整個(gè)計(jì)算并不是在本地進(jìn)行的,是在Web服務(wù)端進(jìn)行計(jì)算的然后將結(jié)果通過(guò)XML返還給了調(diào)用方的,所以,在運(yùn)行該程序的時(shí)候,WebService程序還必須啟動(dòng),否則會(huì)報(bào)無(wú)法連接遠(yuǎn)程服務(wù)器的異常,如下圖:
?
后臺(tái)代碼如下:
復(fù)制代碼 代碼如下:
using System;??
using System.Configuration;??
using System.Data;??
using System.Linq;??
using System.Web;??
using System.Web.Security;??
using System.Web.UI;??
using System.Web.UI.HtmlControls;??
using System.Web.UI.WebControls;??
using System.Web.UI.WebControls.WebParts;??
using System.Xml.Linq;??
public partial class _Default : System.Web.UI.Page???
{??
??? protected void Page_Load(object sender, EventArgs e)??
??? {??
??? }??
??? protected void Button1_Click(object sender, EventArgs e)??
??? {??
??????? string selectFlag = selectOper.Value;??
??????? localhost.Service web = new localhost.Service();??
??????? if (selectFlag.Equals("+"))??
??????? {??
??????????? Result.Text =(web.addition(double.Parse(Num1.Text),double.Parse(Num2.Text))).ToString();??
??????? }??
??????? else if (selectFlag.Equals("-"))??
??????? {??
??????????? Result.Text = (web.subtract(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString();??
??????? }??
??????? else if (selectFlag.Equals("*"))??
??????? {??
??????????? Result.Text = (web.multiplication(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString();??
??????? }??
??????? else if (selectFlag.Equals("/"))??
??????? {??
??????????? Result.Text = (web.division(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString();??
??????? }??
??? }??
}
復(fù)制代碼 代碼如下:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
??? protected void Page_Load(object sender, EventArgs e)
??? {
??? }
??? protected void Button1_Click(object sender, EventArgs e)
??? {
??????? string selectFlag = selectOper.Value;
??????? localhost.Service web = new localhost.Service();
??????? if (selectFlag.Equals("+"))
??????? {
??????????? Result.Text =(web.addition(double.Parse(Num1.Text),double.Parse(Num2.Text))).ToString();
??????? }
??????? else if (selectFlag.Equals("-"))
??????? {
??????????? Result.Text = (web.subtract(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString();
??????? }
??????? else if (selectFlag.Equals("*"))
??????? {
??????????? Result.Text = (web.multiplication(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString();
??????? }
??????? else if (selectFlag.Equals("/"))
??????? {
??????????? Result.Text = (web.division(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString();
??????? }
??? }
}
?
到此一個(gè)一個(gè)簡(jiǎn)單的WebService的開(kāi)發(fā)和調(diào)用就已經(jīng)完成了,在實(shí)際應(yīng)用中可以根據(jù)自己的需要,寫(xiě)一些功能強(qiáng)大的,復(fù)雜的WebService,不管多么復(fù)雜,整個(gè)流程都是這樣的。

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The method to get the current session ID in PHP is to use the session_id() function, but you must call session_start() to successfully obtain it. 1. Call session_start() to start the session; 2. Use session_id() to read the session ID and output a string similar to abc123def456ghi789; 3. If the return is empty, check whether session_start() is missing, whether the user accesses for the first time, or whether the session is destroyed; 4. The session ID can be used for logging, security verification and cross-request communication, but security needs to be paid attention to. Make sure that the session is correctly enabled and the ID can be obtained successfully.

To extract substrings from PHP strings, you can use the substr() function, which is syntax substr(string$string,int$start,?int$length=null), and if the length is not specified, it will be intercepted to the end; when processing multi-byte characters such as Chinese, you should use the mb_substr() function to avoid garbled code; if you need to intercept the string according to a specific separator, you can use exploit() or combine strpos() and substr() to implement it, such as extracting file name extensions or domain names.

UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

In PHP, the most common method is to split the string into an array using the exploit() function. This function divides the string into multiple parts through the specified delimiter and returns an array. The syntax is exploit(separator, string, limit), where separator is the separator, string is the original string, and limit is an optional parameter to control the maximum number of segments. For example $str="apple,banana,orange";$arr=explode(",",$str); The result is ["apple","bana

JavaScript data types are divided into primitive types and reference types. Primitive types include string, number, boolean, null, undefined, and symbol. The values are immutable and copies are copied when assigning values, so they do not affect each other; reference types such as objects, arrays and functions store memory addresses, and variables pointing to the same object will affect each other. Typeof and instanceof can be used to determine types, but pay attention to the historical issues of typeofnull. Understanding these two types of differences can help write more stable and reliable code.

std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

In PHP, to pass a session variable to another page, the key is to start the session correctly and use the same $_SESSION key name. 1. Before using session variables for each page, it must be called session_start() and placed in the front of the script; 2. Set session variables such as $_SESSION['username']='JohnDoe' on the first page; 3. After calling session_start() on another page, access the variables through the same key name; 4. Make sure that session_start() is called on each page, avoid outputting content in advance, and check that the session storage path on the server is writable; 5. Use ses

ToaccessenvironmentvariablesinPHP,usegetenv()orthe$_ENVsuperglobal.1.getenv('VAR_NAME')retrievesaspecificvariable.2.$_ENV['VAR_NAME']accessesvariablesifvariables_orderinphp.iniincludes"E".SetvariablesviaCLIwithVAR=valuephpscript.php,inApach
