webservice调用技术从表面上看Webservice就是一个应用程序它向外界暴露出_第1页
webservice调用技术从表面上看Webservice就是一个应用程序它向外界暴露出_第2页
webservice调用技术从表面上看Webservice就是一个应用程序它向外界暴露出_第3页
webservice调用技术从表面上看Webservice就是一个应用程序它向外界暴露出_第4页
webservice调用技术从表面上看Webservice就是一个应用程序它向外界暴露出_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、也很容易举出COM求的情况。Web 是一套标准,它定义了应用程序如何在Web上实现互操 也很容易举出COM求的情况。Web 是一套标准,它定义了应用程序如何在Web上实现互操 上写Web service ,只通过Web service 标准对这些服务进行查询和 不管你的Webservice是用什么工具,什么语言写出来的,只要你用SOAP协议通过 Web service。客户根据WSDLSOAP请求消息。Web service都是放在Web服务器 (如IIS) SOAP请求会被嵌入在一个HTTPVB6程序来说,Web serviceSOAP Toolkit协同工作的ASP页面或ISAPI 。而对

2、VB.NET程序来说,Webservice请处理器则是一个.NET Framework自带的ISAPI SOAP请求,调用WebserviceSOAP应答。Web服务SOAP 应答后,会再通过HTTP 应答的方式把它送回到客户端。2 基本概念Web service 建好以后,其他人就会去调用它。简单对象过程调用( RPC)方法来调用Web 可扩展的标记语言(XML)是Web service于分析外,XML主要的优点在于它既是越性更重要的。XML解决了数据表示说怎么去扩展这套数据类型。例如,整形数到底代表什么?16位,32位,还是64位?这些细节对实现互操作性都是很重要的。W3C 制定的XML

3、Schema(XSD)就是专门解决这Web service就是用XSD来作为其数据类型系统的。当用某种语言(如VB.NET或C #)来构造一个Web service时,为了符合Web service标准,所有使用的数据类型都必须被转换为XSD 类型。WSDL(Web Description T请求中,发送到Web服务器来。WebWeb NET)来构建你的WebserviceSOAP Toolkit或者.NET。作为一个WindowsCOMDCOM从表面上看,Web service 就是一个应用程序,它向外界出一个能够通过Web进行调用的API。这就是说,你能够用编程的方法通过Web 来调用这个

4、应用程序。Web service Web WSML(Web Meta 用于描述WSDL里提供的方法与实现该方法的COM WSML(Web Meta 用于描述WSDL里提供的方法与实现该方法的COM 。举个例子,在应用程序里加入一个新页面,必须先建立好用户界面(Web页面),并在这个HTML形式,最后还要把“结果页”送回HTML 表单,客户端的编程就简单多了。 SOAP 20%Web Service的各种程序集成起来,而这种集成将花费很大的开发力量。应用程序经常需要从运行在也常常需要集成起来。通过WebService个例Web Service,订单执行程序可以把“Add Order”“长项三:

5、B2B 供 “系统 运行成本就相对较低。不过,WebService并不像EDIB2B集成的 “系统 运行成本就相对较低。不过,WebService并不像EDIB2B集成的完整解决方案。Web ServiceB2B集成的一个关键部分,还需要许多其它的部分才 辑”出来,成为WebService上的时间和成本,让许多原本无法承受EDIB2BWeb Service在允许重用代码的同时,可以重用代码背后的数据。使用Web WebServiceWebService Web Service 这些功能。一旦他们把这些功能都通过Web Service “将来,许多应用程序都会利用WebService/Web S

6、ervice 的混合结构可以在应用程序中使用的Web Service 提供的功能也可以把自己的应用程序功能通过Web Service 4.如何调用4.0 webservice客户端:取得服务端的服务描述文件SOAP 回应消息返回给用户。SOAPXML的任何信息,就可以生成和使用一个oap Toolkit 2.0SOAP 回应消息返回给用户。SOAPXML的任何信息,就可以生成和使用一个oap Toolkit 2.0通过提供两个COM对象nt和生成所有Web VB 或是SoapSerializer对象,用于生成Soap消息。按 消息,作为Payload通过HttpConnector4.1 Bul

7、letin Web Toolkit apache soap public class nt public ic void main(String args) Exception URL url = new URL public class nt public ic void main(String args) Exception URL url = new URL Registry smr = new Registry StringDeserializer sd = new smr.mapTypes (Constants.NS_URI_SOAP_ENC, new QName (, sult),

8、 null, null, / SOAPHTTPConnection st = new / Call call = new Call (); Registry(smr);ObjectURI call.setEncodingStyleURI Vector params = new , , null);Response resp = try resp = call.invoke (url, catch (SO xception e) ln(Caught xception ( + e.getFaultCode () ): + e.getMessage (); / if (resp != null &

9、!resp.generatedFault() Parameter ret = resp.getReturnValue(); Object value = ret.getValue();ln (Answer- + else Fault fault/ if (resp != null & !resp.generatedFault() Parameter ret = resp.getReturnValue(); Object value = ret.getValue();ln (Answer- + else Fault fault = resp.getFault ln (Generated faul

10、t: ln ( ln ( Code = + =+4. 3 aspJscript% LANGUAGE = JScript var WSDL_URL = var a, b, var a b= nt= ntProperty(ServerHTTPRequest) = ASP中运行 需要设置ServerHTTPRequestres = webservice 演示Result: 4. 4在asp中使用vbscript调用% LANGUAGE 4. 4在asp中使用vbscript调用% LANGUAGE = VBScript Dim Const WSDL_URL = set nt = ntProperty

11、(ServerHTTPRequest) = Dim = nt.test(23, Result: 4. 5使用C#Visual项目windows应用程序。C#在解决方案资源管理器中添加改名*;namespace public class Form1 : System.Windows.Forms.Label label1; System.Windows.Forms.TextBoxtextBox1;.Container =public protected overridenamespace public class Form1 : System.Windows.Forms.Label label1;

12、 System.Windows.Forms.TextBoxtextBox1;.Container =public protected override void e( bool ing if( ing if (components != e( ing #region Windows Form Designer generated private this.label1 = new this.textBox1 = new this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Pothis.label1.Nam

13、e = (88, this.label1.Size = new System.Drawing.Size(91, 14); this.label1.TabIndex = 0;this.label1.Text = Webservice演示this.textBox1.Location = new (88, this.textBox1.Name = textBox1; this.textBox1.TabIndex = 1; this.textBox1.Text = textBox1;aseSize = new System.Drawing.Size(6, 14); ntSize = new Syste

14、m.Drawing.Size(292, 273);this.Controls.AddRange(newthis.Name = this.Text = C#Webservie演示this.Load += new System.Even sic void Application.Run(new this.Name = this.Text = C#Webservie演示this.Load += new System.Even sic void Application.Run(new private void sender, System.EventArgs 的名字.Service1 cc=new 的

15、名字var WSDL_URL = WScript.echo(Connecting: + var Calc = WScript.CreateObject(MSSOAP.SoapC Calc.mssoapinit(WSDL_URL, , , )var Answer = Calc.test(14,28) WScript.Echo(14+28= + Answer)Visual项目windows应用程序。Basic在解决方案资源管理器中添加*Visual项目windows应用程序。Basic在解决方案资源管理器中添加*Public Class *InheritsSystem.Windows.Forms.

16、Form #Region Windows 窗体设计器生成的代码 Public Sub New() End Protected Overloads b e(ByVal ing )If ing If Not (components Is Nothing) End IfEnd End Private components Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Private Sub InitializeCo Me

17、.Label1 = New System.Windows.Forms.Label() Me.TextBox1 = New System.Windows.Forms.TextBox() Me.Label1.AutoSize = Me.Label1.Location = New Me.Label1.Name = (96, Me.Label1.Size = New System.Drawing.Size(91, 14) Me.Label1.TabIndex = 0Me.Label1.Text = Webservice演示Me.TextBox1.Location = New System.Drawin

18、g.Po Me.TextBox1.Name = TextBox1 Me.TextBox1.TabIndex = 1Me.TextBox1.Text = (88, aseSize = New System.Drawing.Size(6, ntSize = New System.Drawing.Size(292, Me.Controls.AddRange(New System.Windows.Forms.Control() Me.T extBox1, Me.Label1)Me.Name = Me.Text = VB.net webserive演示 End Sub #EndRegionPrivate

19、 Sub Form1_Load(ByVal sender As System.Object, ByVal e As SntSize = New System.Drawing.Size(292, Me.Controls.AddRange(New System.Windows.Forms.Control() Me.T extBox1, Me.Label1)Me.Name = Me.Text = VB.net webserive演示 End Sub #EndRegionPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As S

20、 ystem.EventArgs) Handles MyBase.LoadDim cc As yundan.Service1 = New yundan.Service1() TextBox1.Text = cc.test(12, 123)End End 需Soap Type :位置:”C:Program FilesCommon FilesMSSoapBinaries Dim cc As New EXE新建工程Option Dim cc As Private Sub cc.mssoapinitMe.Text3.Text = cc.test(CEnd SubOption Const WSDL_UR

21、L = WScript.echo Connecting: & WSDL_URL Dim CalcCSet Calc = CreateObject(MSSOAP.SoapCCalc.mssoapinit WSDL_URLDim Answer = WScript.Echo 14+28= & #import msxml3.dll using namespace MSXML2;#import C:Program FilesCommon Elude(IStream, ISequentialStream,Answer = WScript.Echo 14+28= & #import msxml3.dll u

22、sing namespace MSXML2;#import C:Program FilesCommon Elude(IStream, ISequentialStream, EGER, GER, STG, _FILETIME) using namespace 新建工程MFC AppWizard(exe) Mcntstep1基本 #pragma #endif / _MSC_VER #define s / Exclude rarely-used rom #include / MFC core and standard MFC sMFC Automation / MFC support ernet E

23、xplorer 4 #ifndef #include / MFC support for Windows Common #endif / #import using namespace #import C:Program FilesCommon exclude(IStream, ISequentialStream, EGER, NTEGER, STG, _FILETIME) using #import using namespace #import C:Program FilesCommon exclude(IStream, ISequentialStream, EGER, NTEGER, S

24、TG, _FILETIME) using namespace #define MSG(message) N| MB_APPLMODAL);goto cleanup; |#define CHECK_HRESULT(hr, message) if (FAILED(hr) MSG(message); Visual C+ will insert additional declarations y e the previous #endif / !defined(AFX_STDAFX_H 045CD307_9518_4AF1_8CE3_8FFE 38D1ACB2 INCLUDED_)/ nt.h : m

25、ain header file for the NT #if 2ECC NT_H #define NT_H 9A397DA6_5A62_4AEF_BE5E_6C7629322ECC #if _MSC_VER #pragma #endif / _MSC_VER #ifndef #error include stdafx.h before including this file for PCH #include / main / / See nt.cpp for the ion of #ifndef #error include stdafx.h before including this fil

26、e for PCH #include / main / / See nt.cpp for the ion of this class ntApp : public / / ClassWizard generated virtual function /BOOL / ntDlg.h : header #if 834CAD07 NTDLG_H #define 07 NTDLG_H #if _MSC_VER #pragma #endif / _MSC_VER / ntDlg class ntDlg : public /Construction void AssignpRef(VARIANT *var

27、1, VARIANT assignItem(LVITEM *item, iSubItem, STR boolDestroyTree(); void Execute(); HTREEITEM AddtoTree(HTREEITEM hParent, HTREEITEM AssignpRef(VARIANT *var1, VARIANT assignItem(LVITEM *item, iSubItem, STR boolDestroyTree(); void Execute(); HTREEITEM AddtoTree(HTREEITEM hParent, HTREEITEM TSTR pszD

28、ata, mask, IUnknown * ntDlg(CWnd* pParent = / Dialog enum IDD = NT_DIALOG / / ntDlg.cpp : ion #ifdef #define new DEBUG_NEW #undef THIS_FILEsic char THIS_FILE = FILE / ntDlg ntDlg(CWnd* pParent : ntDlg:IDD, m_strParameter = _T(); m_strURL = _T();/function: parameters: No description: Pass the paramet

29、ers and invoke the operation, get the res and update theparameters and the resultm_strParameter = _T(); m_strURL = _T();/function: parameters: No description: Pass the parameters and invoke the operation, get the res and update theparameters and the result returns: void ;= =bstrWSDLFileName = bstrWS

30、MLFileName = name1024 = = = = = = =name1024 = = = = = = = = = = *pArg = *pRef = =if != -pArg = new pRef = new MSG(Could not get parameters from parameter if (!pArg) | MSG(There is no enough if MSG(Please if (!pArg) | MSG(There is no enough if MSG(Please select an = CoCreateInstance( nt), NULL, SERVE

31、R, (void CHECK_HRESULT(hr, Can not create the object of the CLSID_SoapCli if MSG(Can not create the object of the / we need to have wsdl file and port and service name for mssoapinit hPort = m_TreeCtrl.GetParentItem(hItem);if MSG(Can not get bstrPort = m_TreeCtrl.GetItemText(hPort).AllocSysString();

32、 if (bstrPort = NULL)MSG(Can not get Port hService = m_TreeCtrl.GetParentItem(hPort); if (!hService)MSG(Can not get Service bstrService = m_TreeCtrl.GetItemText(hService).AllocSysString(); if (bstrService = NULL)MSG(Can not get Service bstrWSDLFileName = m_strURL.AllocSysString(); if (bstrWSDLFileNa

33、me = NULL)MSG(Can not get WSDL file hr = pCCHECK_HRESULT(hr, Soap initiation / get the selected functions hr = pCCHECK_HRESULT(hr, Soap initiation / get the selected functions if (pstrFunctionName = MSG(Could not function = nNumParameters = NamedArgs = /there is a pass by ref, and I will use pRef as

34、 parameter = nCount = / the loop should be number of parameters for (nCounter=0; nCounter m_Parameters.GetItemCount() ; nCounte r +)/ I need to get the value of parameter and its type assignItem(&Item, LVIF_PARAM,nCounter,0,0,0); assignItem(&Item1,LVIF_TEXT,nCounter,2,name,sizeof(name);if (m_Paramet

35、ers.GetItem(&Item) = 0) MSG(Could not get item!);if (m_Parameters.GetItem(&Item1) = MSG(Could not get / we will not fill the arguments with ret_cast(Item.lParam)-if (IsInput != / I have to fill this array in reverse order bacause the server expects it in reverse order:VariantInit(&pRefnNumParameters

36、 - nCount -/ I keep the parameter as vTempVariable.vt = strVal = / the for type and value of / I keep the parameter as vTempVariable.vt = strVal = / the for type and value of parameter is / the value with correct type and value is o hr = CHECK_HRESULT(hr, Could not get Variant hr = :VariantChangeTyp

37、e(&pArgnCount,&vTempVariable,VAR IANT_NOUSEROVERRIDE, (unsigned short) ltype);CHECK_HRESULT(hr, Can not convert Variant Type! Either Function selected or Parameter is Wrong or / assign the correct parameter to pRef and indicate it is FpRefnNumParameters - nCount -1 = pArgnCount.vt AssignpRef(&pRefnN

38、umParameters - nCount -nCount / get the ID of = nt-GetIDsOfNames(IID_NULL, &pstrFunctionName, 1, ALE_SYSTEM_DEFAULT, CHECK_HRESULT(hr, Taking IDs / calling the = Fn, IID_NULL, ULT, DISPATCH_METHOD, &result, &excnfo, 0); CHECK_HRESULT(hr, Function call Failed!);/ update the for(nCounter = 0; nCounter

39、 m_Parameters.GetItemCount() ; nC if (nCounter hr = :VariantChangeType(&variantbstrtemp,&pArgnCounter,V for(nCounter = 0; nCounter m_Parameters.GetItemCount() ; nC if (nCounter hr = :VariantChangeType(&variantbstrtemp,&pArgnCounter,V hr = :VariantChangeType(&variantbstrtemp,&result,VARIANT_N CHECK_H

40、RESULT(hr, Variant could not be CString assignItem(&Item, LVIF_TEXT,nCounter,2, (LPTSTR)(LPCTSTR)Text,: if (m_Parameters.SetItem(&Item) = MSG(Could not set Item to for(nCounter = 0; nCounter ; if delete if delete function: if delete function: parameters: (NMHDR* pNMHDR, LRESULT* description: for eac

41、h row of list, it calls the returns: void CMCntDlg:OnDeleteitemListparam(NMHDR* pNMHDR, LRESULT* pR / We have to release t I filled with object of *tempVar = if ret_cast (tempVar- *pResult = function: parameters: (NMHDR* pNMHDR, LRESULT* description: for each tree elements, it calls the Release retu

42、rns: void ntDlg:OnDeleteitemTree(NMHDR* pNMHDR, LRESULT* / We have to release t I filled with *tempVar = if / We have to release t I filled with *tempVar = if ret_cast (tempVar- *pResult = function: parameters: (NMHDR* pNMHDR, LRESULT* description: for selection on tree, it updates the returns: void

43、 ntDlg:OnSelchangedTree(NMHDR* pNMHDR, LRESULT* / if the selected is operation, update the list with its NMTREEVIEW* pNMTreeView = IUnknown *pUnk = ret_cast(pNMTreeView-if (! IWSDLOperation *pOper = ret_cast(&pOper)erface( uuidof(IWSDLOperation), if ist() != MSG(Parameter list can not be *pResult =

44、if function:if ist() != MSG(Parameter list can not be *pResult = if function: parameters: No description: takes the service, ports and operations and fills the returns: void ;chech if wsdl file is given, if not, return if (CheckforURL() = -1)/ delete the tree if (!DestroyTree()if a tree exist and ca

45、nt be deleted, =;/ the name of wsdl =;/ the name of wsdl bstrWSDLFileName = if (bstrWSDLFileName = hr = CoCreateInstance(_uuidof(WSDLReader), OC_SERVER, uuidof(IWSDLReader),CHECK_HRESULT(hr, Can not create the object of the / loading needs wsdl and wsml files, but I dont know wsml file an d I pass h

46、r = pIWSDLReader-Load(bstrWSDLFileName, CHECK_HRESULT(hr, Loading WSDL and WSML files / get soap hr = pIWSDLReader-CHECK_HRESULT(hr, Can not get if MSG(Can not get )while(hr = pIEnumWSDLServi ched) = S_OK)-Next(1, &pIWSDLService, / at least one time this loop should go inside;/ at least one time this loop should go inside; if it does not, the fla g wont be updated/ so we can not continue and should destroy the tree if any / get service hr = pIWSDLService-get_name(&bstrServiceName); CHECK_HRESULT(hr, Can not get Service n

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论