WCFサービスはIIS 7.0でWASで信託します.
WCFサービスはIIS 7.0でWAS信託WASを使用する:
Windowsアクティブサービス(WAS)は、IIS 7の一部であり、独立したインストールと配置も可能です.IISとWASの主な違いは、WASがHTTPを使用することに限定されず、すべての利用可能なWCF伝送プロトコル、ポートとキューをサポートすることであり、サポートされているプロトコルは、HTTP、TCP、IPC、MSMQを含む.
WASは、多くの自己管理に基づく強力な機能を提供しており、アプリケーション・プール、回収メカニズム、アイドル時間管理(Idle Time Mannagement)、アイデンティティ管理(Identity Management)、および分離(Isolation)を含む.ホストプロセスは状況に応じてこれらの機能を選択して使用することができます.
次はDEMOを通してWASチューブ(net.tcpバインディング)を紹介します.
開発環境:Visual Studio 2010+Net Frame ework 4.0
実行環境:Windows Server 2008 R 2+IIS 7+WAS
1、WCf Service Libraryを作成します.主なコードは以下の通りです.
5、WASとWCFをインストールしてアクティブ化する【HTTP活性化と非HTTP活性化】:サービスマネージャをオープンする->追加機能->選択.NET Frame Work 3.5.1とWindowsプロセスアクティベーションサービスは、以下の図のとおりです. .
次のステップをクリックしてインストールします.インストールしましたので、画面はすでにインストールされていますので、次のステップとインストールボタンは使えません.
6、インストールが完了したら、サービスの中でNetTcpActivator、NetPipeActivator、NetTcpPortSharingとWASサービスがすでに起動しているのを見ることができます.
7、ここにきて、WASとWCFは【HTTP活性化と非HTTP活性化】のインストールが完了し、成功しました.次はDefault Web Siteで複数のプロトコルが自動的にバインディングされていることを確認します.コマンドラインはinetmgrを入力し、IISマネージャを開き、Drfaul Web Siteを右クリックし、バインディングをクリックします.
バインディングをクリックした後、net.tcpなどの非httpプロトコルが見えない場合、右側の追加をクリックしてhttpプロトコルバインディングを追加することができます.
以上はhttpバインディングを追加するために、net.tcpバインディングを起動する必要があります.WASHost Service->管理アプリケーション->をクリックして、高度な設定を行い、net.tcpバインディングを起動します.
IISマネージャによる非httpバインディングの追加に加え、コマンドラインによる非httpバインディングの追加も可能です.
8、コマンドラインにバインディングを追加します.コマンドラインにcmdを入力して、C:\Windows\System 32\inetsrv>ディレクトリに入り、アプリcmdを入力して、システムはapcmdのヘルプ情報を提供してから、appcmd list siteを入力します.
8.1、エンドポイントtcpバインディングを設定し、入力:appcmd set site「Default Web Site」-+bindings.[protocol=net.tcp',bindingInformation='808:*]を入力します.
8.2、tcpバインディングを有効にし、appcmd list appを入力し、リストされたアプリケーションに従って、appcmd set app「Default Web Site/WASHost Service」/enabledProtocs:http、net.tcpを入力します.
コマンドラインにバインディングプロセスを追加します.
(wwww.washott.comはhostファイルに項目を追加します.127..1 ws.washots.com)下記の情報が見られます.
このメタデータが見えるのは、設定ファイルに「[serviceMetadata]http GetEnbaled="true"/"」、「endpoint address="mex"binding="netTcpBinding"contract="IMetadatExchange"bindingConfignation="を設定しているからです.
10、Client項目を作成し、Service引用を追加して、次の図のようにする.
完了後、Programクラスにコードを追加します.主要コードは以下の通りです.
12、サービスの呼び出し中にErrerが現れた場合:
これで、委託管理(Hosting)-WAS委託(net.tcp)の紹介が終わりました.
Windowsアクティブサービス(WAS)は、IIS 7の一部であり、独立したインストールと配置も可能です.IISとWASの主な違いは、WASがHTTPを使用することに限定されず、すべての利用可能なWCF伝送プロトコル、ポートとキューをサポートすることであり、サポートされているプロトコルは、HTTP、TCP、IPC、MSMQを含む.
WASは、多くの自己管理に基づく強力な機能を提供しており、アプリケーション・プール、回収メカニズム、アイドル時間管理(Idle Time Mannagement)、アイデンティティ管理(Identity Management)、および分離(Isolation)を含む.ホストプロセスは状況に応じてこれらの機能を選択して使用することができます.
次はDEMOを通してWASチューブ(net.tcpバインディング)を紹介します.
開発環境:Visual Studio 2010+Net Frame ework 4.0
実行環境:Windows Server 2008 R 2+IIS 7+WAS
1、WCf Service Libraryを作成します.主なコードは以下の通りです.
//
[ServiceContract(Namespace
=
"
http://schemas.xinhaijulan.com/demos/WASHost
"
)]
public
interface
IWASHostService { [OperationContract]
string
HelloWCF(
string
str); }
//
public
class
WASHostService : IWASHostService {
public
string
HelloWCF(
string
str) {
return
string
.Format(
"
Get message from client is : {0}
"
, str); } }
2、ASP.NETブランクサイトを作成し、Service Library参照を追加し、サービスファイル「WASHost Service.svc」を追加します.コードは以下の通りです.
<%
@ ServiceHost Language
=
"
C#
"
Debug
=
"
true
"
Service
=
"
ServiceLibrary.WASHostService
"
%>
3、Web.co.nfigファイルを追加すると以下のようになります.
<?
xml version
=
"
1.0
"
?>
<
configuration
>
<
system.web
>
<
compilation debug
=
"
true
"
targetFramework
=
"
4.0
"
/>
</
system.web
>
<
system.serviceModel
>
<
services
>
<
service name
=
"
ServiceLibrary.WASHostService
"
behaviorConfiguration
=
"
MetaDataBehavior
"
>
<
endpoint address
=
""
binding
=
"
netTcpBinding
"
contract
=
"
ServiceLibrary.IWASHostService
"
bindingConfiguration
=
"
myNetTcp
"
/>
<endpoint address="mex" binding="netTcpBinding" contract="IMetadataExchange" bindingConfiguration="mexTcp" />
</
service
>
</
services
>
<
bindings
>
<netTcpBinding> <binding name="myNetTcp" portSharingEnabled="true"> </binding> <binding name="mexTcp" portSharingEnabled="true"> <security mode="None" /> </binding> </netTcpBinding>
</
bindings
>
<
behaviors
>
<
serviceBehaviors
>
<
behavior name
=
"
MetaDataBehavior
"
>
<serviceMetadata httpGetEnabled="true" />
<
serviceDebug includeExceptionDetailInFaults
=
"
false
"
/>
</
behavior
>
</
serviceBehaviors
>
</
behaviors
>
<
serviceHostingEnvironment multipleSiteBindingsEnabled
=
"
true
"
/>
</
system.serviceModel
>
</
configuration
>
4、ウェブサイトをコンパイルして、success、そしてコマンドラインで入力します.inetmgr、IISマネージャを開けて、Default Web Siteにアプリケーションを追加します.5、WASとWCFをインストールしてアクティブ化する【HTTP活性化と非HTTP活性化】:サービスマネージャをオープンする->追加機能->選択.NET Frame Work 3.5.1とWindowsプロセスアクティベーションサービスは、以下の図のとおりです. .
次のステップをクリックしてインストールします.インストールしましたので、画面はすでにインストールされていますので、次のステップとインストールボタンは使えません.
6、インストールが完了したら、サービスの中でNetTcpActivator、NetPipeActivator、NetTcpPortSharingとWASサービスがすでに起動しているのを見ることができます.
7、ここにきて、WASとWCFは【HTTP活性化と非HTTP活性化】のインストールが完了し、成功しました.次はDefault Web Siteで複数のプロトコルが自動的にバインディングされていることを確認します.コマンドラインはinetmgrを入力し、IISマネージャを開き、Drfaul Web Siteを右クリックし、バインディングをクリックします.
バインディングをクリックした後、net.tcpなどの非httpプロトコルが見えない場合、右側の追加をクリックしてhttpプロトコルバインディングを追加することができます.
以上はhttpバインディングを追加するために、net.tcpバインディングを起動する必要があります.WASHost Service->管理アプリケーション->をクリックして、高度な設定を行い、net.tcpバインディングを起動します.
IISマネージャによる非httpバインディングの追加に加え、コマンドラインによる非httpバインディングの追加も可能です.
8、コマンドラインにバインディングを追加します.コマンドラインにcmdを入力して、C:\Windows\System 32\inetsrv>ディレクトリに入り、アプリcmdを入力して、システムはapcmdのヘルプ情報を提供してから、appcmd list siteを入力します.
8.1、エンドポイントtcpバインディングを設定し、入力:appcmd set site「Default Web Site」-+bindings.[protocol=net.tcp',bindingInformation='808:*]を入力します.
8.2、tcpバインディングを有効にし、appcmd list appを入力し、リストされたアプリケーションに従って、appcmd set app「Default Web Site/WASHost Service」/enabledProtocs:http、net.tcpを入力します.
コマンドラインにバインディングプロセスを追加します.
Microsoft Windows [
6.1
.
7600
] (c)
2009
Microsoft Corporation。 。 C:\Users\Administrator
>
cd\ C:\
>
cd windows C:\Windows
>
cd system32 C:\Windows\System32
>
cd inetsrv C:\Windows\System32\inetsrv
>
appcmd IIS 。 APPCMD ( ) ( )
<
>
</
1: 1 ...
>
: SITE APP VDIR APPPOOL CONFIG WP REQUEST HTTP MODULE BACKUP TRACE ( ,
/?
, “appcmd.exe site
/?
”) :
/?
。
/
text
<
:value
>
( ) 。
/
text:
*
。
/
text:
<
attribute
>
。
/
xml XML 。
/
in
。
/
in
or
-
XML 。
/
xml 。
/
config
<
:
*>
。
/
config:
*
。
/
metadata 。
/
commit 。 、“site”、 “app”、“parent” “url” , “apphost”、“webroot” “machine”。
/
debug 。
-
“
!
” , “
/!
debug:value” “debug” 。 C:\Windows\System32\inetsrv
>
appcmd list site SITE
"
demo
"
(id:
2
,bindings:http
/*
:80:www.demo.com,state:Started) SITE "HelloWCF" (id:3,bindings:http/*:80:www.hellowcf.com,state:Started) SITE "Default Web Site" (id:1,bindings:http/*:80:www.washost.com,net.tcp/808:*,n et.pipe/*,net.msmq/localhost,msmq.formatname/localhost,state:Started) C:\Windows\System32\inetsrv>appcmd list app APP "demo/" (applicationPool:Demo) APP "HelloWCF/" (applicationPool:HelloWCF) APP "Default Web Site/" (applicationPool:Default Web Site) APP "Default Web Site/MSMQ" (applicationPool:Default Web Site) APP "Default Web Site/WASHostService" (applicationPool:Default Web Site)
9、ここまでWASホストサービスの設定が完了しました.ブラウザで開きます.svcファイルはメタデータが見えるかどうかをテストします.入力:http://www.washost.com/WASHostService/WASHostService.svc (wwww.washott.comはhostファイルに項目を追加します.127..1 ws.washots.com)下記の情報が見られます.
このメタデータが見えるのは、設定ファイルに「[serviceMetadata]http GetEnbaled="true"/"」、「endpoint address="mex"binding="netTcpBinding"contract="IMetadatExchange"bindingConfignation="を設定しているからです.
10、Client項目を作成し、Service引用を追加して、次の図のようにする.
完了後、Programクラスにコードを追加します.主要コードは以下の通りです.
class
Program {
static
void
Main(
string
[] args) {
using
(Server.WASHostServiceClient client
=
new
Server.WASHostServiceClient()) { Console.WriteLine(
"
--------WAS NET.TCP BEGIN--------
"
); Console.WriteLine(client.HelloWCF(
"
Hello WCF
"
)); Console.WriteLine(
"
--------WAS NET.TCP END--------
"
); Console.ReadLine(); } Console.ReadLine(); } }
この時、Clientプロジェクトの中で、システムは自動的に一つのap.co nfigファイルを生成しています.主なコードは以下の通りです.
<?
xml version
=
"
1.0
"
encoding
=
"
utf-8
"
?>
<
configuration
>
<
system.serviceModel
>
<
bindings
>
<
netTcpBinding
>
<
binding name
=
"
NetTcpBinding_IWASHostService
"
closeTimeout
=
"
00:01:00
"
openTimeout
=
"
00:01:00
"
receiveTimeout
=
"
00:10:00
"
sendTimeout
=
"
00:01:00
"
transactionFlow
=
"
false
"
transferMode
=
"
Buffered
"
transactionProtocol
=
"
OleTransactions
"
hostNameComparisonMode
=
"
StrongWildcard
"
listenBacklog
=
"
10
"
maxBufferPoolSize
=
"
524288
"
maxBufferSize
=
"
65536
"
maxConnections
=
"
10
"
maxReceivedMessageSize
=
"
65536
"
>
<
readerQuotas maxDepth
=
"
32
"
maxStringContentLength
=
"
8192
"
maxArrayLength
=
"
16384
"
maxBytesPerRead
=
"
4096
"
maxNameTableCharCount
=
"
16384
"
/>
<
reliableSession ordered
=
"
true
"
inactivityTimeout
=
"
00:10:00
"
enabled
=
"
false
"
/>
<
security mode
=
"
Transport
"
>
<
transport clientCredentialType
=
"
Windows
"
protectionLevel
=
"
EncryptAndSign
"
/>
<
message clientCredentialType
=
"
Windows
"
/>
</
security
>
</
binding
>
</
netTcpBinding
>
</
bindings
>
<
client
>
<
endpoint address
=
"
net.tcp://cs/WASHostService/WASHostService.svc
"
binding
=
"
netTcpBinding
"
bindingConfiguration
=
"
NetTcpBinding_IWASHostService
"
contract
=
"
Server.IWASHostService
"
name
=
"
NetTcpBinding_IWASHostService
"
>
<
identity
>
<
servicePrincipalName value
=
"
host/CS
"
/>
</
identity
>
</
endpoint
>
</
client
>
</
system.serviceModel
>
</
configuration
>
11、クライアントを実行して、下記の図を入力します.12、サービスの呼び出し中にErrerが現れた場合:
An unhandled exception of type
'
System.ServiceModel.EndpointNotFoundException
'
occurred
in
mscorlib.dll Additional information: The message could not be dispatched because the service at the endpoint address
'
net.tcp://cs/WASHostService/WASHostService.svc
'
is
unavailable
for
the protocol of the address.
ServiceModelを再インストールして解決してください.「C:\Windows\Microsoft.NET\Frame ework 64\v 4.0.3 0319」ServiceModelReg.exe-r」は、ServiceModelがインストールしたバージョンの問題として、以下の通りです.
C:\Users\Administrator
>
cd\ C:\
>
cd C:\Windows\Microsoft.NET\Framework64\v4.
0.30319
C:\Windows\Microsoft.NET\Framework64\v4.
0.30319
>
ServiceModelReg
-
r Microsoft (R) WCF
/
WF registration tool version
4.0
.
0.0
Copyright (c) Microsoft Corporation. All rights reserved. Administration utility that manages the installation and uninstallation of WCF and WF components on a single machine. [SC] ChangeServiceConfig2 [SC] ChangeServiceConfig2 [SC] ChangeServiceConfig2 [SC] ChangeServiceConfig2 [SC] ChangeServiceConfig2 [SC] ChangeServiceConfig2 [SC] ChangeServiceConfig2 [SC] ChangeServiceConfig2 [Warning]The HTTP
namespace
reservation already exists.
他の問題があれば、「telnet ipポート番号」を通じてサービス側がこのポートを開いているかどうかを確認してください.これで、委託管理(Hosting)-WAS委託(net.tcp)の紹介が終わりました.