2013-05-08 12 views
7

コールバックを使用してWCFでデータをストリーミングしています。 WCFはIISでホストされています(デフォルト設定で、プロトコルにnet.tcpが追加されました)。WCF overセキュリティモードのnet.tcpなし例外

私たちは、WCFのセキュリティを無効にしようとしているので、私はクライアントとサーバーの両方で、「なし」にセキュリティモードを設定したが、私は次て、CommunicationExceptionを得る:

ソケット接続中止されました。これは、 メッセージの処理中にエラーが発生したか、リモートホストの または受信したネットワークリソースの問題により受信タイムアウトを超過したことが原因です。ローカルソケット タイムアウトは'00:00:59.8439844 'でした。

ストリームセキュリティは http://www.w3.org/2005/08/addressing/anonymousで必要ありませんが、何のセキュリティコンテキスト されています。私は、サービス上でトレースを入れているとTraceViewerは私に次の例外(System.ServiceModel.ProtocolException)を与える

交渉された。これは、リモートエンドポイント のバインディングからStreamSecurityBindingElementが欠落しているために発生している可能性があります。

クライアントのProgram.cs:

using System; 
using System.ServiceModel; 
using WcfClient.ServiceReference1; 

class Program { 
    static void Main() { 
     Callback callback = new Callback(); 
     InstanceContext context = new InstanceContext(callback); 
     Service1Client service1Client = new Service1Client(context, 
                  "NetTcpBinding_IService1"); 


     service1Client.GetData(0); 
     Console.Read(); 
     service1Client.Stop(); 
    } 
} 

internal class Callback : IService1Callback { 
    public void StreamSignalData(int[] result) { 
     foreach (int i in result) { 
      Console.WriteLine(DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + 
           ": " + i); 
     } 
    } 
} 

クライアントのapp.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="NetTcpBinding_IService1"> 
      <security mode="None" /> 
     </binding> 
     </netTcpBinding> 
     <wsDualHttpBinding> 
     <binding name="WSDualHttpBinding_IService1"> 
      <reliableSession ordered="true" /> 
      <security mode="None" /> 
     </binding> 
     </wsDualHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost/wcf-error/Service1.svc" 
     binding="wsDualHttpBinding" 
     bindingConfiguration="WSDualHttpBinding_IService1" 
     contract="ServiceReference1.IService1" 
     name="WSDualHttpBinding_IService1" /> 
     <endpoint address="net.tcp://localhost/wcf-error/Service1.svc" 
     binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService1" 
     contract="ServiceReference1.IService1" name="NetTcpBinding_IService1"> 
     </endpoint> 
    </client> 
    </system.serviceModel> 
</configuration> 

WCF Service1.svc.cs

using System; 
using System.Net.Security; 
using System.ServiceModel; 
using System.Threading; 

[ServiceContract(SessionMode = SessionMode.Required, 
       CallbackContract = typeof(IStreamCallback), 
       ProtectionLevel = ProtectionLevel.None)] 
public interface IService1 { 
    [OperationContract] 
    void GetData(int value); 

    [OperationContract] 
    void Stop(); 
} 

public interface IStreamCallback { 
    [OperationContract(IsOneWay = true)] 
    void StreamSignalData(int[] result); 
} 

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] 
[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] 
public class Service1 : IService1 { 
    private Timer _timer; 

    private readonly IStreamCallback _callback = 
      OperationContext.Current.GetCallbackChannel<IStreamCallback>(); 
    public void GetData(int value) { 
     _timer = new Timer(StreamData, null, 0, 500); 
    } 

    public void Stop() { 
     _timer.Dispose(); 
    } 

    private void StreamData(object state) { 
     int[] randomNumbers = new int[50]; 
     Random random = new Random(); 
     for (int i = 0; i < 50; i++) { 
      randomNumbers[i] = random.Next(100); 
     } 
     _callback.StreamSignalData(randomNumbers); 
    } 
} 

WCFのWeb.config

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation targetFramework="4.0" debug="true"/> 
    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="netTcpBinding" > 
      <security mode="None" /> 
     </binding> 
     </netTcpBinding> 
     <wsDualHttpBinding> 
     <binding name="wsDualHttpBinding"> 
      <security mode="None" /> 
     </binding> 
     </wsDualHttpBinding> 
    </bindings> 
    <protocolMapping> 
     <add scheme="http" binding="wsDualHttpBinding"/> 
    </protocolMapping> 
    <services> 
     <service name="Service"> 
     <endpoint address="" binding="wsDualHttpBinding" 
      bindingConfiguration="wsDualHttpBinding" 
      name="EndPointHTTP" contract="WcfService1.IService1"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" name="mex" 
      contract="IMetadataExchange" /> 
     <endpoint binding="netTcpBinding" bindingConfiguration="netTcpBinding" 
      name="EndPointTCP" contract="WcfService1.IService1" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <useRequestHeadersForMetadataAddress /> 
      <dataContractSerializer /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

これが何であるか任意のアイデア? Googleのヒットのほとんどは、クライアントとサーバーの設定が同じである(つまり、セキュリティはnone)が、エラーが見つからないようです。 StreamSecurityBindingElementのためにグーグルで は、私はあなたの問題を複製することができませんでしたが、私は同じ設定といくつかのものを持っている...いや良いexplenationsで

+0

ログにエラーのある側(クライアント/サービス)はどちらですか? –

+0

@PetarVučetinサービス。 – ahoibakk

+0

@PetarVučetin私はクライアントにトレースをかけようとしましたが、それはすでにそれが投げている例外以外の情報は私に与えません。 – ahoibakk

答えて

1

を思い付いた私は気づいた:

は、あなたのWCF Service1.svc.csでnamesapaceを作成します。

namespace WcfService1 
    { 
     [ServiceContract(SessionMode = SessionMode.Required, 
      CallbackContract = typeof (IStreamCallback), 
      ProtectionLevel = ProtectionLevel.None)] 
     public interface IService1 
     { 
     ..... 
     [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] 
     [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] 
     public 

    class Service1 : IService1 
    { 

<service name="Service"><service name="WcfService1.Service1">でなければなりません。サービス名がフルです。サービスのタイプ。 configに

サービスセクション:

<services> 
    <service name="WcfService1.Service1"> 
     <endpoint address="" binding="wsDualHttpBinding" 
      bindingConfiguration="wsDualHttpBinding" 
      name="EndPointHTTP" contract="WcfService1.IService1"> 
      <identity> 
       <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" name="mex" 
      contract="IMetadataExchange" /> 
     <endpoint binding="netTcpBinding" bindingConfiguration="netTcpBinding" 
      name="EndPointTCP" contract="WcfService1.IService1" /> 
    </service> 
</services> 

WCF Service1.svc。CS

using System; 
using System.Net.Security; 
using System.ServiceModel; 
using System.Threading; 

namespace WcfService1 
{ 
    [ServiceContract(SessionMode = SessionMode.Required, 
     CallbackContract = typeof (IStreamCallback), 
     ProtectionLevel = ProtectionLevel.None)] 
    public interface IService1 
    { 
     [OperationContract] 
     void GetData(int value); 

     [OperationContract] 
     void Stop(); 
    } 

    public interface IStreamCallback 
    { 
     [OperationContract(IsOneWay = true)] 
     void StreamSignalData(int[] result); 
    } 

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] 
    [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] 
    public class Service1 : IService1 
    { 
     private Timer _timer; 

     private readonly IStreamCallback _callback = 
      OperationContext.Current.GetCallbackChannel<IStreamCallback>(); 

     public void GetData(int value) 
     { 
      _timer = new Timer(StreamData, null, 0, 500); 
     } 

     public void Stop() 
     { 
      _timer.Dispose(); 
     } 

     private void StreamData(object state) 
     { 
      int[] randomNumbers = new int[50]; 
      Random random = new Random(); 
      for (int i = 0; i < 50; i++) 
      { 
       randomNumbers[i] = random.Next(100); 
      } 
      _callback.StreamSignalData(randomNumbers); 
     } 
    } 
} 

コールバック

あなたは_callback.StreamSignalData(randomNumbers)を扱うことを確認してください。クライアントが切断されたとき通信の例外が発生します。

+0

あなたのご意見ありがとうございますが、残念ながらそれは私の問題を解決しませんでした – ahoibakk

+0

それは奇妙です。まあ - 私は "それは自分のコンピュータで動作する"バッジを得た: –

関連する問題