日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

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

新聞中心

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

當(dāng) .asmx處理程序由 HTTP 管道調(diào)用之后,它會(huì)通過(guò)查看在 .asmx 文件中發(fā)現(xiàn)的 WebService 聲明來(lái)確定要檢查哪個(gè) .NET 類(lèi)。然后,它會(huì)查看傳入的 HTTP 消息中的信息,以便正確地確定要在被引用類(lèi)中調(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 消息中,確實(shí)有兩段信息可用來(lái)確定要在該類(lèi)中調(diào)用哪種方法:SOAPAction 頭或請(qǐng)求元素的名稱(chēng)(例如,soap:Body 元素中元素的名稱(chēng))。在本例中,任何一個(gè)都指出了發(fā)送方想調(diào)用的方法的名稱(chēng)。

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

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

 
 
 
  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(因?yàn)槲覀儗⑺@式定義為該值)。例如,下面的 HTTP 請(qǐng)求消息調(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ā)一個(gè)異常(以后會(huì)詳細(xì)介紹如何處理異常)。如果您不想依賴(lài) SOAPAction 頭來(lái)進(jìn)行方法調(diào)度,則可以用 [SoapDocumentService] 屬性的 RoutingStyle 屬性來(lái)批注該類(lèi),以便指示 .asmx 處理程序使用請(qǐng)求元素的名稱(chēng)。如果這樣做的話,可能還應(yīng)該指出 WebMethod 不需要 SOAPAction 值(通過(guò)將它們的值設(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 值,而是使用請(qǐng)求元素的名稱(chēng)。例如,對(duì)于 Add 方法,該處理程序希望請(qǐng)求元素的名稱(chēng)是 Add(來(lái)自 http://example.org/math 命名空間),如下面的 HTTP 請(qǐng)求消息中所示:

 
 
 
  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 消息時(shí),它做的第一件重要事情就是確定如何將該消息調(diào)度到相應(yīng)的 WebMethod。但是,在能夠?qū)嶋H調(diào)用該方法之前,它必須將傳入的 XML 映射到 .NET 對(duì)象。


當(dāng)前名稱(chēng):.asmx處理程序提供的功能之消息調(diào)度
當(dāng)前地址:http://www.dlmjj.cn/article/dpshgho.html