ASP.NETでのWebサービス開発に関するメモ
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
] [
Twitter
]
開始行:
→ASP.NET関連
#contents
※注:ここで書いてる話はVisual Studio .NET 2003と2005の話...
*参考Web [#o35dcb89]
-[[Visual Studio .NETとWebサービス>http://itpro.nikkeibp....
-[[ASP.NET Webサービスが機能する方法>http://www.microsoft...
-[[クライアントサイド・スクリプトからXML Webサービスを非...
-[[Webサービスパフォーマンスの向上>http://www.microsoft.c...
-[[Webサービスクライアントの作り方(.NET)>http://www.micro...
-[[ASP.NET クイックチュートリアル XML Webサービスとは>htt...
*プロジェクト作成 [#ke7d208c]
-【VS.NET 2005の場合】プロジェクトの新規作成→Webサイト→AS...
--SP1以後は普通のプロジェクトとしても作成が可能になった模...
-【VS.NET 2003の場合】プロジェクトの新規作成→プロジェクト...
*.asmxファイル [#zc484a40]
-.asmxファイル
テキストファイル
-Webサービスには先頭のディレクティブとして以下の記述が必要
<%@ WebService Language="C#" Class="<クラス名>" %>
-ソースが別になっている場合はこうなる
(例)
<%@ WebService Language="c#" Codebehind="SrvTst.asmx.cs"...
-ただしクラスがプリコンパイル済みの場合はソースは要らない。
*サービス用のクラス [#ka04cef3]
-System.Web.Services名前空間をインクルードする
-サービスのクラスは WebService クラスから派生させる
--ただしWebServiceクラスの継承は必須ではない
-パブリッククラスである必要がある
-サービス用メソッドには属性として[WebMethod]をつける
*Webサービス(もしくはSOAP)の名前空間とは? [#eb88e1b7]
-ここでいう名前空間とは、SOAPで使うXMLの名前空間
-要はそのサービスを他のサービスと区別できれば良いので被ら...
**「規定の名前空間とは?」 [#l41b95ff]
-最初に作ったのを実行する時に出てくるメッセージの意味は?
・この Web サービスは、http://tempuri.org/ を既定の名前...
・XML Web サービスをパブリックにする前に、既定の名前空間...
「XML Web サービス名前空間」を変更しないといけないらしい。
**どうやって変更する? [#g598a41d]
-→ サービスのクラスの属性でセットする
[WebService(Namespace="http://<適当な名前>/")]
public class SrvTest : System.Web.Services.WebService
{
public SrvTest()
{
//CODEGEN: この呼び出しは、ASP.NET Web サービス デザイ...
InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
*複数端末から同時に呼ばれたときの動作は? [#j7119a7e]
-再入は起きるのか?→起きません
-2つの呼び出しは同じプロセスの2つのスレッドで動いている...
-したがって、クラスにstaticなメンバを持つことで複数の処理...
*クライアント側から参照するサービスのURL変更 [#m23fd3ec]
-サービスクラスのUrlプロパティを変更する
//サービスのURL WSDLのURLじゃなくてもOKな模様
svc.Url = "http://www.hoge.net/hogeSvc/hogeSvc.asmx"
-ヘルプにて「Web サービスの Url プロパティの設定 」を参照
*WSE(Web Services Enhancements) [#h7b7c9f0]
-[[WSE Home@MS>http://msdn.microsoft.com/en-us/webservice...
-[[WSEのインストール>http://www.atmarkit.co.jp/fdotnet/sp...
--[[WSE 3.0 Download page>http://www.microsoft.com/downlo...
--[[WSE 2.0 Download page>http://www.microsoft.com/downlo...
-3.0を入れれば2.0は要らない
**基礎知識 [#g9695143]
-Web上ではWSE1.0に関する記事が多く見つかるのだが、これは...
-[[Web Services Enhancements 1.0 for Microsoft .NET によ...
-[[Web Services Enhancements を使用したアタッチメント付き...
-[[SOAPメッセージとファイル添付>http://www.atmarkit.co.jp...
--DIME仕様、WS-Attachmentについて。
--古い仕様となりつつあるので今後はMTOMを使った方が良いと...
**FAQぽいこと [#a74e5f14]
-SoapContextクラスがインテリセンスに出てこないんだけど?
--→Microsoft.Web.Services(2|3).dllを参照しないとダメです
例)
using Microsoft.Web.Services3;
...
SoapContext ctx = RequestSoapContext.Current;
-Microsoft.Web.Services.dllってどこにあるの?
--→WSEを別途ダウンロードしてきてインストールしないと無い...
--インストールすれば通常は C:\Program Files\Microsoft WSE...
--Webサービスから Microsoft.Web.Services3を参照する
--using Microsoft.Web.Services3;する
--注意:WSE 3.0は ASP.NET 2.0で動作するのが前提
-WSEのHelpファイルが見られないんだけど?
--VISUAL STUDIO.NETのページの「HxS(Microsoft Compiled Hel...
--具体的に言うと、以下のページを参照して該当ファイルにチ...
ms-help://MS.VSCC.v80/dv_vscccommon/local/CollectionMana...
-クライアント側にもWSE3.0をインストールしないといけないの?
--基本的にはその通り
--ただし、クライアント側がClickOnceアプリならば、Microsof...
--その他、.msiでセットアップさせることも可能な模様(未確...
-サービス側プロジェクトの「WSE Settings 3.0...」から出て...
--最初にプロジェクトを作るときに「新規作成」−「プロジェク...
--このプロジェクトはVisual Studio .NET 2005 の SP1から追...
--「新規作成」−「Webサイト…」の下にある「ASP.NET Webサー...
--この現象の原因は不明。おそらくWSEはWebサイトとしてのWeb...
**添付ファイルのサイズ上限について [#p0fdf1df]
-[[WS-Attachmentのファイルサイズについて>http://www.takak...
--WSEの標準設定では、4MBのサイズの制限があります。
--もっと正確に言うと、ASP.NETのHTTPのリクエストメッセージ...
--これらは、Webサービスの構成ファイル(web.config)を編集す...
[ web.configの記述例 ]-----------
<configuration>
<system.web>
<httpRuntime maxRequestLength="8000"
useFullyQualifiedRedirectUrl="true"
executionTimeout="45" />
</system.web>
<microsoft.web.services2>
<messaging>
<maxRequestLength>8000</maxRequestLength>
</messaging>
<diagnostics />
</microsoft.web.services2>
</configuration>
--上の構成ファイルは、8MBに上限を引き上げた例になります。
--httpRuntimeとWSE2.0の2箇所を設定する必要があるのでご注...
--もちろん、ファイルサイズが大きくなればなるほど、多くの...
Webサービスの呼び出しがタイムアウトする恐れがでてきます。
-WSE3.0でMTOM使用の場合はconfigurationタグの記述が多少こ...
サイズを1MBにした例
<configuration>
<microsoft.web.services3>
<messaging>
<maxMessageLength value="1024" />
</messaging>
</microsoft.web.services3>
</configuration>
**WSE3.0でMTOMを使うには? [#n30fea28]
-所定の設定をした上で、普通にByte配列を引数なりクラスメン...
-参考:[[MTOMエンコーディング>http://csharper.blog57.fc2....
-サーバ側:ヘルプの「How to: Enable a Web Service to Send...
-クライアント側:ヘルプの「How to:Send and Receive Large ...
-RequireMtomとは?
--WebServicesClientProtocolクラスのRequireMtom プロパティ...
--これをTRUEにするとメッセージがMTOMエンコーディングされる
--WebServicesClientProtocolクラスは、WSEを使う場合のクラ...
--生成されたプロキシクラスはHogeHoge''Wse'' みたいな名前...
--クライアントとなるプログラムからプロキシクラスのメソッ...
-ASP.NETリクエストのサイズ上限4MBの問題についてはMTOMを使...
**WSE910の例外について [#k98a6342]
-サーバとクライアントの時計の時刻が5分以上ずれていると、...
WSE910: An error happened during the processing of a res...
and you can find the error in the inner exception. You ...
the response message in the Response property.
-Inner Exception:
An error was discovered processing the <Security> header
-Inner Inner Exception:
"WSE066: Timestamp is expired.
This indicates a stale message but may also be caused by...
synchronization between sender and receiver clocks.
Make sure the clocks are synchronized or use
the timeToleranceInSeconds element in the microsoft.web....
configuration section to adjust tolerance
for lack of clock synchronization.
-WSEをかまさない通常のWebサービスであればこの問題は発生し...
-この仕様はセキュリティ上の理由で設けられているものらしい
-参考URL:http://www.developmentnow.com/g/16_2006_4_0_0_72...
--As for the time synchronizing, it
is due to the requirement of the message security and rel...
message it follows the WS-I BSP spec. The SOAP message
transfered(especially for those security specific message...
contains timestamp and a lifetime cycle, this prevent oth...
from performing replay attack. However, use such timestam...
lifetime mechanism require both client-server utilize the...
usually it is the internet time system, and for our scena...
and server boxes should synchronize their system clock:
-参考:[[WS-I BSP(Basic Security Profile) Interoperabilit...
--Message Age and Clock Skew
---The timestamp within a secure message is often critica...
---WSE includes a setting that determines how long a mess...
---To reject messages reliably, you must ensure that cloc...
---The <timeToleranceInSeconds> setting is shared, so cha...
---While the clock skew function can help with interopera...
-対策1:サーバとクライアントの時刻を合わせる
-対策2:Web.Configで以下のような設定をする
<microsoft.web.services3>
<security>
<timeToleranceInSeconds value="3600" /> 許容時間を...
</security>
</microsoft.web.services3>
--この設定はサービス側だけでなく、クライアント側のapp.con...
--app.config記述例
<microsoft.web.services3>
<messaging>
<mtom clientMode="On" />
</messaging>
<security>
<!-- defaultTtlInSeconds value="3600" /-->
<timeToleranceInSeconds value="3600" />
</security>
</microsoft.web.services3>
--timeToleranceInSecondsだけでなくdefaultTtlInSecondsも設...
--上記WS-I BSPでは900秒=15分くらいの設定を推奨している。...
-ヘルプ"<timeToleranceInSeconds> Element "のページより抜粋
--Use the <timeToleranceInSeconds> element when there is ...
--A similar scenario exists for expired security tokens. ...
-参考URL:
--http://forums.msdn.microsoft.com/en-US/asmxandxml/threa...
--http://geeknotes.wordpress.com/2007/03/21/more-wse-issu...
終了行:
→ASP.NET関連
#contents
※注:ここで書いてる話はVisual Studio .NET 2003と2005の話...
*参考Web [#o35dcb89]
-[[Visual Studio .NETとWebサービス>http://itpro.nikkeibp....
-[[ASP.NET Webサービスが機能する方法>http://www.microsoft...
-[[クライアントサイド・スクリプトからXML Webサービスを非...
-[[Webサービスパフォーマンスの向上>http://www.microsoft.c...
-[[Webサービスクライアントの作り方(.NET)>http://www.micro...
-[[ASP.NET クイックチュートリアル XML Webサービスとは>htt...
*プロジェクト作成 [#ke7d208c]
-【VS.NET 2005の場合】プロジェクトの新規作成→Webサイト→AS...
--SP1以後は普通のプロジェクトとしても作成が可能になった模...
-【VS.NET 2003の場合】プロジェクトの新規作成→プロジェクト...
*.asmxファイル [#zc484a40]
-.asmxファイル
テキストファイル
-Webサービスには先頭のディレクティブとして以下の記述が必要
<%@ WebService Language="C#" Class="<クラス名>" %>
-ソースが別になっている場合はこうなる
(例)
<%@ WebService Language="c#" Codebehind="SrvTst.asmx.cs"...
-ただしクラスがプリコンパイル済みの場合はソースは要らない。
*サービス用のクラス [#ka04cef3]
-System.Web.Services名前空間をインクルードする
-サービスのクラスは WebService クラスから派生させる
--ただしWebServiceクラスの継承は必須ではない
-パブリッククラスである必要がある
-サービス用メソッドには属性として[WebMethod]をつける
*Webサービス(もしくはSOAP)の名前空間とは? [#eb88e1b7]
-ここでいう名前空間とは、SOAPで使うXMLの名前空間
-要はそのサービスを他のサービスと区別できれば良いので被ら...
**「規定の名前空間とは?」 [#l41b95ff]
-最初に作ったのを実行する時に出てくるメッセージの意味は?
・この Web サービスは、http://tempuri.org/ を既定の名前...
・XML Web サービスをパブリックにする前に、既定の名前空間...
「XML Web サービス名前空間」を変更しないといけないらしい。
**どうやって変更する? [#g598a41d]
-→ サービスのクラスの属性でセットする
[WebService(Namespace="http://<適当な名前>/")]
public class SrvTest : System.Web.Services.WebService
{
public SrvTest()
{
//CODEGEN: この呼び出しは、ASP.NET Web サービス デザイ...
InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
*複数端末から同時に呼ばれたときの動作は? [#j7119a7e]
-再入は起きるのか?→起きません
-2つの呼び出しは同じプロセスの2つのスレッドで動いている...
-したがって、クラスにstaticなメンバを持つことで複数の処理...
*クライアント側から参照するサービスのURL変更 [#m23fd3ec]
-サービスクラスのUrlプロパティを変更する
//サービスのURL WSDLのURLじゃなくてもOKな模様
svc.Url = "http://www.hoge.net/hogeSvc/hogeSvc.asmx"
-ヘルプにて「Web サービスの Url プロパティの設定 」を参照
*WSE(Web Services Enhancements) [#h7b7c9f0]
-[[WSE Home@MS>http://msdn.microsoft.com/en-us/webservice...
-[[WSEのインストール>http://www.atmarkit.co.jp/fdotnet/sp...
--[[WSE 3.0 Download page>http://www.microsoft.com/downlo...
--[[WSE 2.0 Download page>http://www.microsoft.com/downlo...
-3.0を入れれば2.0は要らない
**基礎知識 [#g9695143]
-Web上ではWSE1.0に関する記事が多く見つかるのだが、これは...
-[[Web Services Enhancements 1.0 for Microsoft .NET によ...
-[[Web Services Enhancements を使用したアタッチメント付き...
-[[SOAPメッセージとファイル添付>http://www.atmarkit.co.jp...
--DIME仕様、WS-Attachmentについて。
--古い仕様となりつつあるので今後はMTOMを使った方が良いと...
**FAQぽいこと [#a74e5f14]
-SoapContextクラスがインテリセンスに出てこないんだけど?
--→Microsoft.Web.Services(2|3).dllを参照しないとダメです
例)
using Microsoft.Web.Services3;
...
SoapContext ctx = RequestSoapContext.Current;
-Microsoft.Web.Services.dllってどこにあるの?
--→WSEを別途ダウンロードしてきてインストールしないと無い...
--インストールすれば通常は C:\Program Files\Microsoft WSE...
--Webサービスから Microsoft.Web.Services3を参照する
--using Microsoft.Web.Services3;する
--注意:WSE 3.0は ASP.NET 2.0で動作するのが前提
-WSEのHelpファイルが見られないんだけど?
--VISUAL STUDIO.NETのページの「HxS(Microsoft Compiled Hel...
--具体的に言うと、以下のページを参照して該当ファイルにチ...
ms-help://MS.VSCC.v80/dv_vscccommon/local/CollectionMana...
-クライアント側にもWSE3.0をインストールしないといけないの?
--基本的にはその通り
--ただし、クライアント側がClickOnceアプリならば、Microsof...
--その他、.msiでセットアップさせることも可能な模様(未確...
-サービス側プロジェクトの「WSE Settings 3.0...」から出て...
--最初にプロジェクトを作るときに「新規作成」−「プロジェク...
--このプロジェクトはVisual Studio .NET 2005 の SP1から追...
--「新規作成」−「Webサイト…」の下にある「ASP.NET Webサー...
--この現象の原因は不明。おそらくWSEはWebサイトとしてのWeb...
**添付ファイルのサイズ上限について [#p0fdf1df]
-[[WS-Attachmentのファイルサイズについて>http://www.takak...
--WSEの標準設定では、4MBのサイズの制限があります。
--もっと正確に言うと、ASP.NETのHTTPのリクエストメッセージ...
--これらは、Webサービスの構成ファイル(web.config)を編集す...
[ web.configの記述例 ]-----------
<configuration>
<system.web>
<httpRuntime maxRequestLength="8000"
useFullyQualifiedRedirectUrl="true"
executionTimeout="45" />
</system.web>
<microsoft.web.services2>
<messaging>
<maxRequestLength>8000</maxRequestLength>
</messaging>
<diagnostics />
</microsoft.web.services2>
</configuration>
--上の構成ファイルは、8MBに上限を引き上げた例になります。
--httpRuntimeとWSE2.0の2箇所を設定する必要があるのでご注...
--もちろん、ファイルサイズが大きくなればなるほど、多くの...
Webサービスの呼び出しがタイムアウトする恐れがでてきます。
-WSE3.0でMTOM使用の場合はconfigurationタグの記述が多少こ...
サイズを1MBにした例
<configuration>
<microsoft.web.services3>
<messaging>
<maxMessageLength value="1024" />
</messaging>
</microsoft.web.services3>
</configuration>
**WSE3.0でMTOMを使うには? [#n30fea28]
-所定の設定をした上で、普通にByte配列を引数なりクラスメン...
-参考:[[MTOMエンコーディング>http://csharper.blog57.fc2....
-サーバ側:ヘルプの「How to: Enable a Web Service to Send...
-クライアント側:ヘルプの「How to:Send and Receive Large ...
-RequireMtomとは?
--WebServicesClientProtocolクラスのRequireMtom プロパティ...
--これをTRUEにするとメッセージがMTOMエンコーディングされる
--WebServicesClientProtocolクラスは、WSEを使う場合のクラ...
--生成されたプロキシクラスはHogeHoge''Wse'' みたいな名前...
--クライアントとなるプログラムからプロキシクラスのメソッ...
-ASP.NETリクエストのサイズ上限4MBの問題についてはMTOMを使...
**WSE910の例外について [#k98a6342]
-サーバとクライアントの時計の時刻が5分以上ずれていると、...
WSE910: An error happened during the processing of a res...
and you can find the error in the inner exception. You ...
the response message in the Response property.
-Inner Exception:
An error was discovered processing the <Security> header
-Inner Inner Exception:
"WSE066: Timestamp is expired.
This indicates a stale message but may also be caused by...
synchronization between sender and receiver clocks.
Make sure the clocks are synchronized or use
the timeToleranceInSeconds element in the microsoft.web....
configuration section to adjust tolerance
for lack of clock synchronization.
-WSEをかまさない通常のWebサービスであればこの問題は発生し...
-この仕様はセキュリティ上の理由で設けられているものらしい
-参考URL:http://www.developmentnow.com/g/16_2006_4_0_0_72...
--As for the time synchronizing, it
is due to the requirement of the message security and rel...
message it follows the WS-I BSP spec. The SOAP message
transfered(especially for those security specific message...
contains timestamp and a lifetime cycle, this prevent oth...
from performing replay attack. However, use such timestam...
lifetime mechanism require both client-server utilize the...
usually it is the internet time system, and for our scena...
and server boxes should synchronize their system clock:
-参考:[[WS-I BSP(Basic Security Profile) Interoperabilit...
--Message Age and Clock Skew
---The timestamp within a secure message is often critica...
---WSE includes a setting that determines how long a mess...
---To reject messages reliably, you must ensure that cloc...
---The <timeToleranceInSeconds> setting is shared, so cha...
---While the clock skew function can help with interopera...
-対策1:サーバとクライアントの時刻を合わせる
-対策2:Web.Configで以下のような設定をする
<microsoft.web.services3>
<security>
<timeToleranceInSeconds value="3600" /> 許容時間を...
</security>
</microsoft.web.services3>
--この設定はサービス側だけでなく、クライアント側のapp.con...
--app.config記述例
<microsoft.web.services3>
<messaging>
<mtom clientMode="On" />
</messaging>
<security>
<!-- defaultTtlInSeconds value="3600" /-->
<timeToleranceInSeconds value="3600" />
</security>
</microsoft.web.services3>
--timeToleranceInSecondsだけでなくdefaultTtlInSecondsも設...
--上記WS-I BSPでは900秒=15分くらいの設定を推奨している。...
-ヘルプ"<timeToleranceInSeconds> Element "のページより抜粋
--Use the <timeToleranceInSeconds> element when there is ...
--A similar scenario exists for expired security tokens. ...
-参考URL:
--http://forums.msdn.microsoft.com/en-US/asmxandxml/threa...
--http://geeknotes.wordpress.com/2007/03/21/more-wse-issu...
ページ名: