vb.netでの設定ファイルでもある『web.config』について自分が苦労した内容を抜粋しました。
- 受信データ容量のサイズアップ <system.serviceModel>
- RESTコントローラの指定 <system.serviceModel>
- レスポンスのフォーマット形式をJSONにする <system.serviceModel>
- ログファイル、My.Application.Logの設定<system.diagnostics>
・受信データ容量のサイズアップ <system.serviceModel>
多めのデータをJSONで送信しようとしたら『413 Request Entity Too Large』のエラーがでたので
webHttpBindingタグで各サイズを指定します。
※サンプルは『basicHttpBinding』ばかりでしたが、これだと自分の環境では解決できなかったので『webHttpBinding』を使います
<bindings>
<webHttpBinding>
<binding maxBufferPoolSize ="2147483647" maxBufferSize ="2147483647"
maxReceivedMessageSize ="2147483647" />
</webHttpBinding>
</bindings>
・RESTコントローラの指定 <system.serviceModel>
<services>
<service name="proc1.Test1">
<endpoint address="" behaviorConfiguration="proc1.Proc1Behavior"
binding="webHttpBinding" contract="proc1.Test1" />
</service>
<service name="proc1.Test2">
<endpoint address="" behaviorConfiguration="proc1.Proc1Behavior"
binding="webHttpBinding" contract="proc1.Test2" />
</service>
</services>
・レスポンスのフォーマット形式をJSONにする <system.serviceModel>
defaultOutgoingResponseFormatでJsonに設定
※これがないとJSONに余分な値がセットされる
<behaviors>
<endpointBehaviors>
<behavior name="proc1.Proc1Behavior">
<!-- <enableWebScript /> -->
<webHttp defaultOutgoingResponseFormat="Json" />
</behavior>
</behaviors>
・ログファイル、My.Application.Logの設定<system.diagnostics>
<system.diagnostics>
<sources>
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLogListener" />
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<!-- 下記プロパティはデバックで警告になるが、実行はできるので無視する
・"autoflush" : 自動的にフラッシュの指定
・"location" : ログの保存場所を変更する
・"basefilename" : ログファイル名
・"customlocation" : 出力フォルダ名 ※※ ここを環境に合わせて修正する ※※
・"logfilecreationschedule" : ログファイル名の最後に日付を付加する
"バイク検索システムエラーログ-2019-06-14.log"
-->
<add name="FileLogListener"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener,
Microsoft.VisualBasic, Version=8.0.0.0,
Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"
initializeData="FileLogListenerWriter"
autoflush="true"
location="Custom"
basefilename="バイク検索システムエラーログ"
customlocation="C:\file\ログ\"
logfilecreationschedule="Daily" />
</sharedListeners>
</system.diagnostics>