0

我有一个需要服务器\客户端和客户端\服务器通信的 WCF 服务。我使用 .NET 远程处理开始了这个任务,但有几个人告诉我,我可能应该研究 WCF。

所以任务从我学习 WCF 开始,我能够成功地创建我的服务和订阅我的事件的应用程序!服务器通知了客户端,大家都很高兴,直到我将实际的服务器应用程序移到我的服务器上。然后大量的问题开始了。

我的客户端配置

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
          switchValue="Information, ActivityTracing"
          propagateActivity="true">
      <listeners>
          <add name="traceListener"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData="c:\log\Traces.svclog"  />
      </listeners>
   </source>
 </sources>
</system.diagnostics>
<system.serviceModel>
    <bindings>
        <wsDualHttpBinding>
            <binding name="WSDualHttpBinding_ICompany" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00" />
                <security mode="Message">
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsDualHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://MyServer:8731/Design_Time_Addresses/WCFCallbacks/Message/"
            binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_ICompany"
            contract="ServiceReference1.ICompany" name="WSDualHttpBinding_ICompany">
        </endpoint>
    </client>
</system.serviceModel>
</configuration>

我的服务器配置

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
<system.serviceModel>
<services>
  <service name="WCFTest.Company" behaviorConfiguration="WCFTest.Company">
    <host>
      <baseAddresses>
        <add baseAddress = "http://localhost:8731/Design_Time_Addresses/WCFCallbacks/Message/" />
      </baseAddresses>
    </host>
    <endpoint address ="" binding="wsDualHttpBinding" contract="WCFTest.ICompany">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="WCFTest.Company">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

现在我在客户端上设置 app.config 的方式是在实际服务器上运行服务,然后在 VS 2010 中将我的 ServiceReference 指向该服务器。它成功生成了app.config!此外,当我运行客户端应用程序时,我可以成功运行 netstat 并看到我的客户端确实已连接。问题是我收到超时错误、SSPI 错误等。跟踪日志如此复杂和混乱,我无法理解它。

我现在的问题是,谁能告诉我我做错了什么?另外,我是否应该继续使用 .NET Remoting(我没有使用 .NET Remoting 的有效解决方案)?请记住,我必须保持双工类型的连接。

谢谢你的时间!

编辑 1

这是我的网络统计:

TCP xxx.xxx.xxx.xxx:8731 主机名:63444 已建立

编辑 2

好吧,我最终使用了 NetTcpBinding,这些解释了为什么 wsDualHttpBinding 难以实现。然后我用这篇文章来创建我的配置。

这是我最终得到的结果:

服务器配置

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
<system.serviceModel>
<services>
  <service name="WCFTest.Company" behaviorConfiguration="WCFTest.Company">
    <host>
      <baseAddresses>
        <add baseAddress = "net.tcp://localhost:8731/WCFTest/Company" />
      </baseAddresses>
    </host>
    <endpoint address ="net.tcp://localhost:8731/WCFTest/Company" binding="netTcpBinding" contract="WCFTest.ICompany">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="WCFTest.Company">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

客户端配置

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <sources>
  <source name="System.ServiceModel"
          switchValue="Information, ActivityTracing"
          propagateActivity="true">
    <listeners>
      <add name="traceListener"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="c:\log\Traces.svclog"  />
    </listeners>
  </source>
</sources>
</system.diagnostics>
<system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="NetTcpBinding_ICompany" 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://MyServer:8731/WCFTest/Company"
            binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ICompany"
            contract="ServiceReference1.ICompany" name="NetTcpBinding_ICompany">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>
</configuration>

我真的希望微软停止提供糟糕的例子。想到我对 Duplex 的唯一实现是使用 wsDualHttpBinding,这真是令人沮丧。他们甚至没有提到 NetTcpBinding,您必须在这些技术方面拥有大量经验才能了解其中的区别。至少对我来说,我的编程生涯还很年轻。感谢两位花时间解释 NetTcpBinding 并提供示例的人,他们极大地帮助了我在这里的实现。

4

0 回答 0