ラベル WCF の投稿を表示しています。 すべての投稿を表示
ラベル WCF の投稿を表示しています。 すべての投稿を表示

2015年11月1日日曜日

net.tcpでの通信

SvcEditorで操作した。
■netTcpBindingでの接続
    ・web.config
        ・netTcpBindingでバインドを作成する
        ・エンドポイントを追加し
          binding:netTcpBinding
          bindingConfiguration:上で作ったバインド
   
        と設定する。

<?xml version="1.0"?>
<configuration>
    <system.serviceModel>
      <bindings>
        <netTcpBinding>
          <binding name="MyTcpBinding">
            <security mode="Transport" /> ※2
          </binding>
        </netTcpBinding>
      </bindings>
      <behaviors>
        <serviceBehaviors>
          <behavior name="TestBehavior">
            <serviceMetadata httpGetEnabled="true" httpGetUrl="" />
            <serviceDebug includeExceptionDetailInFaults="true" />
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <services>
        <service behaviorConfiguration="TestBehavior" name="TcpServiceTest.TestService">
          <endpoint address="" binding="netTcpBinding" bindingConfiguration="MyTcpBinding"
            contract="TcpServiceTest.ITestService" />
          <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
            contract="IMetadataExchange" /> ※3
          <host>
            <baseAddresses>
              <add baseAddress="net.tcp://server/dev/TcpServiceTest.TestService.svc" />
              <add baseAddress="http://server/dev/TcpServiceTest.TestService.svc" />
            </baseAddresses>
          </host>
        </service>
      </services>
    </system.serviceModel>
 <startup>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
 </startup>
</configuration>


    ・クライアント側のexe.config
        ・netTcpBindingでバインドを作成する
        ・エンドポイントを追加し
          binding:netTcpBinding
          bindingConfiguration:上で作ったバインド
   
        と設定する
Visual Studioのサービスの参照を行って作成されたconfigの中身。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors />
        <bindings>
            <netTcpBinding>
                <binding name="MyNetTcpBinding">
                    <security mode="Transport"> ※2
                        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                        <message clientCredentialType="Windows" />
                    </security>
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://server/dev/TcpServiceTest.TestService.svc"
                binding="netTcpBinding" bindingConfiguration="MyNetTcpBinding"
                contract="sr.ITestService" name="NetTcpBinding_ITestService">
              <!-- ※1
                <identity>
                    <userPrincipalName value="username@domain" />
                </identity>
              -->
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

※1
userPrincipalNameの意味がわからない。
指定するとSecurityNegotiationExceptionが発生する。
これにドメインに存在するユーザーIDを入れると上記Exception。
削除または全然関係ない文字列「aaa」とか「adfdfgh@domain」とか
適当な値を入れると正常に通信できる。
謎の設定。

※2
Messageにすると
「通信オブジェクト System.ServiceModel.Channels.ServiceChannel は、状態が Faulted であるため通信に使用できません。」
となってしまう。(調査中)

※3
メタデータの公開が必要なければ削除可

2015年8月27日木曜日

MSDTCでトランザクション処理の設定

WCF net.tcpで、TransactionScopeを利用してトランザクション処理を行った。

ローカル開発環境(WcfSvcHost.exeでのホスト)では正常に処理されるが、
別サーバーのIISでホストさせ、クライアントからアクセスすると、以下のエラーが発生した。

System.ServiceModel.ProtocolException:フローされたトランザクションのマーシャリングを解除できませんでした。次の例外が発生しました:パートナートランザクションマネージャにより、リモートトランザクションまたはネットワークトランザクションのサポートが無効にされました。(HRESULTからの例外: 0x8004D025)

これを回避するには、サーバー、クライアント両方のDistributed Transaction Coodinatorの設定を変更しないといけない。

・dcomcnfg > コンポーネントサービス > マイコンピューター > Distributed Transaction Coodinator > ローカルDTC > プロパティ > セキュリティタブを開く。

・ネットワークDTCアクセスをON
・トランザクションマネージャー通信(受信を許可、送信を許可)をON

これで適用する。

そして、Windowsファイアウォールの詳細設定で以下を有効にする。

<受信の規則>
・分散トランザクションコーディネーター(RPC)
・分散トランザクションコーディネーター(RPC-EPMAP)
・分散トランザクションコーディネーター(TCP受信)

<送信の規則>
分散トランザクションコーディネーター(TCP送信)

2015年8月18日火曜日

WCF構成エディタの場所

【.Net3.5】
c:/Program Files/Microsoft SDKs/Windows/v7.0A/bin

【.Net4.0】
c:/Program Files/Microsoft SDKs/Windows/v7.0/bin/NETFX 4.0 Tools

SrvConfigEditor.exe

2013年10月7日月曜日

WCFをBasic通信で行うために

・IISに基本認証を設定する

 認証→基本認証を有効にする
 ※基本認証がない場合は、役割の追加→サービスの追加→基本認証を追加する。

・web.configの書き換え

 Bindingのこの辺を書き換え 
  <security mode="TransportCredentialOnly">
    <transport clientCredentialType="Basic"/>
    <message clientCredentialType="UserName"/>
  </security>

・app.configも書き換え(こんな感じに)
  <system.serviceModel>
  <bindings>
   <basicHttpBinding>
    <binding name="BasicHttpBinding_Taurus" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="6553600" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
     <readerQuotas maxDepth="32" maxStringContentLength="819200" maxArrayLength="1638400"
       maxBytesPerRead="4096" maxNameTableCharCount="16384" />
     <security mode="TransportCredentialOnly">
      <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
      <message clientCredentialType="UserName" algorithmSuite="Default" />
     </security>

    </binding>
   </basicHttpBinding>
  </bindings>


※参照
10行でズバリ

2013年7月5日金曜日

maxStringContentLength

アプリケーションルートのweb.configに以下のように追記する。
<configuration>
<system.serviceModel>
  <bindings>
   <basicHttpBinding>
    <binding>
     <readerQuotas maxStringContentLength="1000000" />
    </binding>
   </basicHttpBinding>
  </bindings>
</system.serviceModel>
</configuration>

2013年5月22日水曜日

64bit OS でIISを32bit稼働させる方法

アプリケーションプールの詳細設定を開き、32ビットアプリケーションの有効化をtrueにする。

2013年5月21日火曜日

.NET Framework 3.5 WCF HTTP Activation を有効にしたときのエラー

「アセンブリ ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ から型 ‘System.ServiceModel.Activation.HttpModule’ を読み込めませんでした。」

と表示される。

http://msdn.microsoft.com/ja-jp/library/aa751852.aspx
—–以下、抜粋—–
.NET Framework 4 がインストールされている場合に、.NET Framework 3.5 WCF HTTP Activation を有効にすると、このエラーが発生します。この問題を解決するには、Visual Studio 2010 コマンド プロンプト内から次のコマンドを実行します。
aspnet_regiis.exe -i -enable
——————-


つまり

cd "C:\Windows\Microsoft.NET\Framework\v4.0.30319"

aspnet_regiis.exe -i -enable

--------------------------------------------------------------------
Microsoft(R) ASP.NET IIS 登録ツール バージョン 4.0.30319.17929
ローカル コンピューターの ASP.NET をインストールおよびアンインストールするための管理ユーティリティで
す。
Copyright(C) Microsoft Corporation.  All rights reserved.
ASP.NET (4.0.30319.17929) のインストールを開始します。
..........
ASP.NET (4.0.30319.17929) のインストールが完了しました。
--------------------------------------------------------------------


こうしないといけない。

2012年12月28日金曜日

WCFサービス配置 IIS

C:\Windows\System32\inetsrvにenviroment.xmlを置く
アプリケーションルートのbinでもいいかも?

WCFクライアント配布

配布対象にするexeのプロジェクトに、既存のファイルを追加で
必要なdllをすべて追加し、配布パッケージの作成を行う。

WCFサービス配置 binフォルダ

binフォルダは、ビルド時に各サービスの下に配置されるが
IISに配置するには、アプリケーションルート\binに配置する

WCFサービス配置 Web.Config

ビルド時に作成された

・Web.config
・Web.Debug.config
・Web.Release.Config

のうち、

1.Web.Debug.configかWeb.Release.ConfigをWeb.Configに名前を変更
2.<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">を
   <configuration>に変更
3.configurationセクションの中に、元のWeb.configから<system.serviceModel>をコピーしてくる。

2012年12月17日月曜日

DataContractのstring以外のプリミティブ値のDataMember定義

[DataMember(IsRequired = true)]
にしないとサービス側に受け渡されない。

DataContractの参照設定

Client側では、DataContractクラスへの直接の参照は不要。
Visualスタジオのプロキシクラス作成時に自動的に作成されるクラスを使用するため。