日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
.asmx處理程序提供的功能之消息調(diào)度

當(dāng) .asmx處理程序由 HTTP 管道調(diào)用之后,它會通過查看在 .asmx 文件中發(fā)現(xiàn)的 WebService 聲明來確定要檢查哪個 .NET 類。然后,它會查看傳入的 HTTP 消息中的信息,以便正確地確定要在被引用類中調(diào)用哪種方法。要調(diào)用先前示例中顯示的 Add 操作,傳入的 HTTP 消息必須具有如下所示的外觀:

 
 
 
  1. POST /math/math.asmx HTTP/1.1 
  2. Host: localhost 
  3. Content-Type: text/xml; charset=utf-8 
  4. Content-Length: length 
  5. SOAPAction: "http://tempuri.org/Add" 
  6. < soap:Envelope  
  7. xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
  8. > 
  9. < soap:Body> 
  10. < Add xmlns="http://tempuri.org/"> 
  11. < x>33< /x> 
  12. < y>66< /y> 
  13. < /Add> 
  14. < /soap:Body> 
  15. < /soap:Envelope> 

在傳入的 HTTP 消息中,確實有兩段信息可用來確定要在該類中調(diào)用哪種方法:SOAPAction 頭或請求元素的名稱(例如,soap:Body 元素中元素的名稱)。在本例中,任何一個都指出了發(fā)送方想調(diào)用的方法的名稱。

在默認(rèn)情況下,.asmx 處理程序使用 SOAPAction 頭的值來執(zhí)行消息調(diào)度。因此,.asmx 處理程序查看消息中的 SOAPAction 頭,使用 .NET 反射檢查被引用類中的方法。它只考慮標(biāo)記了 [WebMethod] 屬性的方法,但是它可以通過查看每種方法的 SOAPAction 值來正確地確定要調(diào)用哪種方法。由于我們沒有對類中的方法顯式指定 SOAPAction 值,因此,.asmx 處理程序假設(shè) SOAPAction 值將由 Web 服務(wù)的命名空間及其后面的方法名稱組成。而且我們也沒有指定命名空間,因此該處理程序會將 http://tempuri.org 作為默認(rèn)的命名空間。這樣,Add 方法的默認(rèn) SOAPAction 值將是 http://tempuri.org/Add。

您可以自定義 Web 服務(wù)的命名空間,方法是用 [SoapDocumentMethod] 屬性批注自己的 WebMethod,從而使用 [WebService] 屬性以及正確的 SOAPAction 值來批注自己的類,如下所示:

 
 
 
  1. using System.Web.Services; 
  2. using System.Web.Services.Protocols; 
  3. [WebService(Namespace="http://example.org/math")] 
  4. public class MathService 
  5. [WebMethod] 
  6. public double Add(double x, double y) { 
  7. return x + y; 
  8. [WebMethod] 
  9. [SoapDocumentMethod(Action="urn:math:subtract")] 
  10. public double Subtract(double x, double y) { 
  11. return x - y; 
  12. ... 

現(xiàn)在,.asmx 處理程序希望 Add 方法的 SOAPAction 值是 http://example.org/math/Add(使用默認(rèn)試探法),希望 Subtract 方法的 SOAPAction 值是 urn:math:subtract(因為我們將它顯式定義為該值)。例如,下面的 HTTP 請求消息調(diào)用 Subtract 操作:

 
 
 
  1. POST /math/math.asmx HTTP/1.1 
  2. Host: localhost 
  3. Content-Type: text/xml; charset=utf-8 
  4. Content-Length: length 
  5. SOAPAction: "urn:math:subtract" 
  6. < soap:Envelope  
  7. xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
  8. > 
  9. < soap:Body> 
  10. < Subtract xmlns="http://example.org/math"> 
  11. < x>33< /x> 
  12. < y>66< /y> 
  13. < /Subtract> 
  14. < /soap:Body> 
  15. < /soap:Envelope> 

如果 .asmx處理程序未找到與傳入的 HTTP 消息相匹配的 SOAPAction,則它只是引發(fā)一個異常(以后會詳細(xì)介紹如何處理異常)。如果您不想依賴 SOAPAction 頭來進行方法調(diào)度,則可以用 [SoapDocumentService] 屬性的 RoutingStyle 屬性來批注該類,以便指示 .asmx 處理程序使用請求元素的名稱。如果這樣做的話,可能還應(yīng)該指出 WebMethod 不需要 SOAPAction 值(通過將它們的值設(shè)置為空字符串),如下所示:

 
 
 
  1. using System.Web.Services; 
  2. using System.Web.Services.Protocols; 
  3. [WebService(Namespace="http://example.org/math")] 
  4. [SoapDocumentService( 
  5. RoutingStyle=SoapServiceRoutingStyle.RequestElement)] 
  6. public class MathService 
  7. [WebMethod] 
  8. [SoapDocumentMethod(Action="")] 
  9. public double Add(double x, double y) { 
  10. return x + y; 
  11. [WebMethod] 
  12. [SoapDocumentMethod(Action="")] 
  13. public double Subtract(double x, double y) { 
  14. return x - y; 
  15. ... 

在本例中,該處理程序甚至不查看 SOAPAction 值,而是使用請求元素的名稱。例如,對于 Add 方法,該處理程序希望請求元素的名稱是 Add(來自 http://example.org/math 命名空間),如下面的 HTTP 請求消息中所示:

 
 
 
  1. POST /math/math.asmx HTTP/1.1 
  2. Host: localhost 
  3. Content-Type: text/xml; charset=utf-8 
  4. Content-Length: length 
  5. SOAPAction: "" 
  6. < soap:Envelope  
  7. xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
  8. > 
  9. < soap:Body> 
  10. < Add xmlns="http://example.org/math"> 
  11. < x>33< /x> 
  12. < y>66< /y> 
  13. < /Add> 
  14. < /soap:Body> 
  15. < /soap:Envelope> 

因此,當(dāng) .asmx處理程序收到傳入的 HTTP 消息時,它做的第一件重要事情就是確定如何將該消息調(diào)度到相應(yīng)的 WebMethod。但是,在能夠?qū)嶋H調(diào)用該方法之前,它必須將傳入的 XML 映射到 .NET 對象。


當(dāng)前標(biāo)題:.asmx處理程序提供的功能之消息調(diào)度
網(wǎng)頁網(wǎng)址:http://www.5511xx.com/article/dpshgho.html