小马

现在是零将来是无限

导航

Q & A:Does ASP.NET support one-way Web Service operations?

Q Does ASP.NET support one-way Web Service operations?


A Yes, you can implement one-way operations in ASP.NET by setting the OneWay property of the SoapDocumentMethod attribute to true, as shown here:

[WebMethod]
[SoapDocumentMethod(OneWay
=true)]
public void DoSomeWork(string someInfo, string someMoreInfo)
{
    
// do some real work here
    System.Threading.Thread.Sleep(5000);
}
Of course, one-way operations cannot have return values by definition (a SOAP fault is generated if you execute a one-way operation that returns something). By definition, a one-way operation has an input message and no output message, as illustrated by the WSDL generated from this .asmx endpoint:
•••
<portType name="OneWayServiceSoap">
   
<operation name="DoSomeWork">
      
<input message="s0:DoSomeWorkSoapIn" />
   
</operation>
</portType>
•••

 

As soon as ASP.NET finishes deserializing the SOAP message and before it invokes the method, it sends an HTTP response of "202 Accepted" back to the client, indicating it has started processing the request. The client doesn't have to wait for the server to finish processing the request, but the cost is that it won't know the final outcome.

If you invoke this WebMethod using the .asmx-generated HTML test form (not using SOAP), you'll see it wait five seconds before displaying the result. But if you invoke it using the following SOAP message and using an HTTP POST utility (like post.js) as shown in the following code

C:>post http://localhost/oneway/service1.asmx -h 
SOAPAction "urn:example-org:oneway/DoSomeWork" -
Content
-Type "text/xml" -f req.xml
it will return immediately, which truly illustrates the nature of a OneWay request:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  
<soap:Body>
    
<DoSomeWork xmlns="urn:example-org:oneway">
      
<someInfo>string</someInfo>
      
<someMoreInfo>string</someMoreInfo>
    
</DoSomeWork>
  
</soap:Body>
</soap:Envelope>

posted on 2006-03-25 13:37  mahope  阅读(431)  评论(0编辑  收藏  举报