1

我有一个托管 WCF 服务的 Windows 服务和一个与之通信的 WPF 应用程序。WPF 应用程序将位于同一网络上的不同计算机上。发送 WCf 消息时,我无法在两者之间设置安全性。以下是服务器和客户端 app.config 文件:

服务器

    <?xml version="1.0"?>
    <configuration>
      <system.serviceModel>
        <services>
      <service behaviorConfiguration="WCFBehavior" name="WCF.WCFService">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration=""
          name="NetTcpBindingEndpoint" contract="WCF.IWCFService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
          name="MexTcpBindingEndpoint" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8731/WCFService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebHttp">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="WCFBehavior">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceTimeouts transactionTimeout="05:05:00" />
          <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500"
            maxConcurrentInstances="2147483647" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WCFBinding">
          <security mode="None">
          </security>
        </binding>
      </wsDualHttpBinding>
      <webHttpBinding>
        <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
      </webHttpBinding>
    </bindings>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>
</configuration>

客户

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBindingEndpoint" closeTimeout="00:01:05"
          openTimeout="00:00:05" receiveTimeout="00:00:20" sendTimeout="00:00:20"
          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="None">
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:8731/WCFService/" binding="netTcpBinding"
        bindingConfiguration="NetTcpBindingEndpoint" contract="WCFServiceReference.IWCFService"
        name="NetTcpBindingEndpoint">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

我能够让客户端成功连接到服务的唯一方法是,如果我在服务器上创建一个用户,其用户名和密码与我在客户端计算机上使用的帐户相同。如何设置安全性以避免这种情况?由于我可以控制客户端和服务器,因此我不关心是否具有高级别的安全性。

4

2 回答 2

0

您可能需要 UserName 的 CredentialType。现在,您将获得默认的 Windows。

WCF 中的身份验证、授权和身份

于 2012-09-19T11:38:15.393 回答
0

您可以使用服务器上的用户凭据设置数据库。并且为了验证用户请求,如果来自客户端的用户凭据在数据库服务器上得到验证,您可以在服务器上动态创建一个用户。

于 2012-09-19T06:45:29.287 回答