キャッシング - Webサービスの説明にWebMethod属性
WebMethodには6属性があります:
gbvy[W
.Description
.EnableSession
.MessageName
.TransactionOption
.CacheDuration
.BufferResponse
1)Description:
Webサービスメソッドは、情報に記載されている。
ノート。
C#:
[WebMethod(Description="Author:ZFive5Function:HelloWorld")]
publicstringHelloWorld()
{
return"HelloWorld";
}
WSDL:
-<portTypename="Service1Soap">
-<operationname="HelloWorld">
<documentation>Author:ZFive5Function:HelloWorld</documentation>
<inputmessage="s0:HelloWorldSoapIn"/>
<outputmessage="s0:HelloWorldSoapOut"/>
</operation>
</portType>
-<portTypename="Service1HttpGet">
-<operationname="HelloWorld">
<documentation>Author:ZFive5Function:HelloWorld</documentation>
<inputmessage="s0:HelloWorldHttpGetIn"/>
<outputmessage="s0:HelloWorldHttpGetOut"/>
</operation>
</portType>
-<portTypename="Service1HttpPost">
-<operationname="HelloWorld">
<documentation>Author:ZFive5Function:HelloWorld</documentation>
<inputmessage="s0:HelloWorldHttpPostIn"/>
<outputmessage="s0:HelloWorldHttpPostOut"/>
</operation>
</portType>
2)EnableSessionが:
。
C#:
publicstaticinti=0;
[WebMethod(EnableSession=true)]
publicintCount()
{
i=i 1;
returni;
}
つまり、アドレスバーに:
リフレッシュはポイントを表示するには
......
<?xmlversion="1.0"encoding="utf-8"?>
<intxmlns="">19</int>
<?xmlversion="1.0"encoding="utf-8"?>
<intxmlns="">20</int>
......
......
3)MessageNameに:
メインは、名前の変更メソッドのオーバーロード後に達成さ:
C#:
publicstaticinti=0;
[WebMethod(EnableSession=true)]
publicintCount()
{
i=i 1;
returni;
}
[WebMethod(EnableSession=true,MessageName="Count1")]
publicintCount(intda)
{
i=i da;
returni;
}
カウントがカウント1を介してメソッドへのアクセスで最初の訪問番目の方法です!
。
HTTPプロトコルのステートレスな性質から、XMLWebservicesメソッドは、ルートオブジェクトとしてトランザクションに参加することができます。
同じトランザクションXMLWebservicesメソッドでCOMオブジェクトの場合、コンポーネントサービス管理ツールで
。
プロパティは、RequiresNewをTransactionOptionまたは必須されている場合XMLWebservices
別のメソッドの呼び出しまたはRequiresNew TransactionOptionは必須XMLWebservicesメソッド属性
ルートオブジェクト。
例外は、Webサービスメソッドかどうか、キャプチャの方法から、発生した場合、トランザクションは自動的に放棄する。例外が発生した場合は、自動的に配置されます
。
。リクエストを処理する際に、すべてのサービスがされる
XMLWebservicesの実装のケースメソッド。
[WebMethod(TransactionOption=TransactionOption.Disabled)]
NotSupported
。リクエストを処理する際に、すべてのサービスがされる
XMLWebservicesの実装のケースメソッド。
[WebMethod(TransactionOption=TransactionOption.NotSupported)]
トランザクションの場合は、トランザクション内でXMLWebservicesメソッドの動作を示す。トランザクションがないの場合には取引がない場合
作成XMLWebservices。
[WebMethod(TransactionOption=TransactionOption.Supported)]
。
このメソッドは、新しいWebサービスのトランザクションを作成します。。
[WebMethod(TransactionOption=TransactionOption.Required)]
RequiresNew
メソッドは、新しいトランザクションの指示を必要とするXMLWebservices。。
[WebMethod(TransactionOption=TransactionOption.RequiresNew)]
私はクマを喜ばせるためにはここを見て、私は、MSDNをコピーすることができます、ここで練習しないでください
C#
<@WebServiceLanguage="C#"Class="Bank">
<@assemblyname="System.EnterpriseServices">
usingSystem;
usingSystem.Web.Services;
usingSystem.EnterpriseServices;
publicclassBank:WebService{
[WebMethod(TransactionOption=TransactionOption.RequiresNew)]
publicvoidTransfer(longAmount,longAcctNumberTo,longAcctNumberFrom){
MyCOMObjectobjBank=newMyCOMObject();
if(objBank.GetBalance(AcctNumberFrom)<Amount)
//Explicitlyabortthetransaction.
ContextUtil.SetAbort();
else{
//CreditandDebitmethodsexplictlyvotewithin
//thecodefortheirmethodswhethertocommitor
//abortthetransaction.
objBank.Credit(Amount,AcctNumberTo);
objBank.Debit(Amount,AcctNumberFrom);
}
}
}
5)CacheDuration:
キャッシュ時間CacheDuration属性が指定されている。
C#:
publicstaticinti=0;
[WebMethod(EnableSession=true,CacheDuration=30)]
publicintCount()
{
i=i 1;
returni;
}
すなわち、アドレスバーを入力してください:
それにリフレッシュして、!出力は同じではない、30秒にするには。。。
。
。他の一般的なアプリケーションの終了
すべてのバッファにのみした後送信されるように!次のプログラムを検討してください:
C#:
[WebMethod(BufferResponse=false)]
publicvoidHelloWorld1()
{
inti=0;
strings="";
while(i<100)
{
s=s "i<br>";
this.Context.Response.Write(s);
i ;
}
return;
}
[WebMethod(BufferResponse=true)]
publicvoidHelloWorld2()
{
inti=0;
strings="";
while(i<100)
{
s=s "i<br>";
this.Context.Response.Write(s);
i ;
}
return;
}
どのようなデータはすぐに戻ると、してから、1つは、要求側に情報が返されます。。
それ自体が破壊される構造体を返す私の例のWebサービスは、それは、MSDNの例外にも含まれて、しないでください
[C#]
<@WebServiceclass="Streaming"language="C#">
usingSystem;
usingSystem.IO;
usingSystem.Collections;
usingSystem.Xml.Serialization;
usingSystem.Web.Services;
usingSystem.Web.Services.Protocols;
publicclassStreaming{
[WebMethod(BufferResponse=false)]
publicTextFileGetTextFile(stringfilename){
returnnewTextFile(filename);
}
[WebMethod]
publicvoidCreateTextFile(TextFilecontents){
contents.Close();
}
}
publicclassTextFile{
publicstringfilename;
privateTextFileReaderWriterreaderWriter;
publicTextFile(){
}
publicTextFile(stringfilename){
this.filename=filename;
}
[XmlArrayItem("line")]
publicTextFileReaderWritercontents{
get{
readerWriter=newTextFileReaderWriter(filename);
returnreaderWriter;
}
}
publicvoidClose(){
if(readerWriter!=null)readerWriter.Close();
}
}
publicclassTextFileReaderWriter:IEnumerable{
publicstringFilename;
privateStreamWriterwriter;
publicTextFileReaderWriter(){
}
publicTextFileReaderWriter(stringfilename){
Filename=filename;
}
publicTextFileEnumeratorGetEnumerator(){
StreamReaderreader=newStreamReader(Filename);
returnnewTextFileEnumerator(reader);
}
IEnumeratorIEnumerable.GetEnumerator(){
returnGetEnumerator();
}
publicvoidAdd(stringline){
if(writer==null)
writer=newStreamWriter(Filename);
writer.WriteLine(line);
}
publicvoidClose(){
if(writer!=null)writer.Close();
}
}
publicclassTextFileEnumerator:IEnumerator{
privatestringcurrentLine;
privateStreamReaderreader;
publicTextFileEnumerator(StreamReaderreader){
this.reader=reader;
}
publicboolMoveNext(){
currentLine=reader.ReadLine();
if(currentLine==null){
reader.Close();
returnfalse;
}
else
returntrue;
}
publicvoidReset(){
reader.BaseStream.Position=0;
}
publicstringCurrent{
get{
returncurrentLine;
}
}
objectIEnumerator.Current{
get{
returnCurrent;
}
}
}