2011-10-16 4 views
0

WCF를 사용하기 위해 WPF 앱용 코드를 작성했습니다. wcf가 Windows 서비스로 실행 중이며 wpf 프로그램을 클라이언트 시스템에서 실행하고 싶습니다. 나는 서비스와 SQL 서버와 함께 PC에 WPF 애플 리케이션을 설치했다, 거기에서 잘 작동하고있다. 그러나 다른 PC에 wpf 클라이언트를 설치하면 클라이언트 WPF가 서버에 연결할 수 없습니다. 나는 WCF 윈도우 서비스가 lan 사용을 지원하지 않는다는 것을 의미한다. 그러나 나는이 의도를 위해서만 디자인했다. 내 코드를 확인하고 내가 잘못한 곳을 알려주시겠습니까?LAN에서 TCP를 활성화하는 방법

WPF 응용 프로그램 코드 :

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 

    <configSections> 
    </configSections> 
    <connectionStrings> 
    <add name="WorkMateWCF.My.MySettings.workmateConnectionString" 
     connectionString="Data Source=PAVAN-PC;Initial Catalog=WorkMate;Persist Security Info=True;User ID=WorkMateUser;Password=workmateuser" 
     providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --> 
    <system.serviceModel> 
    <services> 
     <service name="WorkMateWCF.WCFLogin"> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="" 
      contract="WorkMateWCF.IWCFLogin"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" 
      contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:8732/WCFLogin" /> 
      </baseAddresses> 
     </host> 
     </service> 
     <service name="WorkMateWCF.WCFCourses"> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="" 
      contract="WorkMateWCF.IWCFCourses"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" 
      contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:8732/WCFCourses" /> 
      </baseAddresses> 
     </host> 
     </service> 
     <service name="WorkMateWCF.WCFStudent"> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="" 
      contract="WorkMateWCF.IWCFStudent"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" 
      contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:8732/WCFStudents" /> 
      </baseAddresses> 
     </host> 
     </service> 
     <service name="WorkMateWCF.WCFBatchImport"> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="" 
      contract="WorkMateWCF.IWCFBatchImport"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" 
      contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:8732/WCFBatchImports" /> 
      </baseAddresses> 
     </host> 
     </service> 
     <service name="WorkMateWCF.WCFFaculty"> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="" 
      contract="WorkMateWCF.IWCFFaculty"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" 
      contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:8732/WCFFaculty" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

</configuration> 

needfull에 대한 기대 :

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
     <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
      <section name="WorkMateWPF.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> 
     </sectionGroup> 
    </configSections> 
    <system.diagnostics> 
     <sources> 
      <!-- This section defines the logging configuration for My.Application.Log --> 
      <source name="DefaultSource" switchName="DefaultSwitch"> 
       <listeners> 
        <add name="FileLog"/> 
        <!-- Uncomment the below section to write to the Application Event Log --> 
        <!--<add name="EventLog"/>--> 
       </listeners> 
      </source> 
     </sources> 
     <switches> 
      <add name="DefaultSwitch" value="Information" /> 
     </switches> 
     <sharedListeners> 
      <add name="FileLog" 
       type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" 
       initializeData="FileLogWriter"/> 
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log --> 
      <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> --> 
     </sharedListeners> 
    </system.diagnostics> 
    <system.serviceModel> 
     <bindings> 
      <netTcpBinding> 
       <binding name="NetTcpBinding_IWCFBatchImport" 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> 
       <binding name="NetTcpBinding_IWCFCourses" 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> 
       <binding name="NetTcpBinding_IWCFFaculty" 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> 
       <binding name="NetTcpBinding_IWCFLogin" 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> 
       <binding name="NetTcpBinding_IWCFStudent" 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://localhost:8732/WCFBatchImports" 
       binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IWCFBatchImport" 
       contract="ServiceBatchImports.IWCFBatchImport" name="NetTcpBinding_IWCFBatchImport"> 
       <identity> 
        <dns value="localhost" /> 
       </identity> 
      </endpoint> 
      <endpoint address="net.tcp://localhost:8732/WCFCourses" binding="netTcpBinding" 
       bindingConfiguration="NetTcpBinding_IWCFCourses" contract="ServiceCourses.IWCFCourses" 
       name="NetTcpBinding_IWCFCourses"> 
       <identity> 
        <dns value="localhost" /> 
       </identity> 
      </endpoint> 
      <endpoint address="net.tcp://localhost:8732/WCFFaculty" binding="netTcpBinding" 
       bindingConfiguration="NetTcpBinding_IWCFFaculty" contract="ServiceFaculty.IWCFFaculty" 
       name="NetTcpBinding_IWCFFaculty"> 
       <identity> 
        <dns value="localhost" /> 
       </identity> 
      </endpoint> 
      <endpoint address="net.tcp://localhost:8732/WCFLogin" binding="netTcpBinding" 
       bindingConfiguration="NetTcpBinding_IWCFLogin" contract="ServiceLogins.IWCFLogin" 
       name="NetTcpBinding_IWCFLogin"> 
       <identity> 
        <dns value="localhost" /> 
       </identity> 
      </endpoint> 
      <endpoint address="net.tcp://localhost:8732/WCFStudents" binding="netTcpBinding" 
       bindingConfiguration="NetTcpBinding_IWCFStudent" contract="ServiceStudents.IWCFStudent" 
       name="NetTcpBinding_IWCFStudent"> 
       <identity> 
        <dns value="localhost" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
    <userSettings> 
     <WorkMateWPF.MySettings> 
      <setting name="Test" serializeAs="String"> 
       <value /> 
      </setting> 
     </WorkMateWPF.MySettings> 
    </userSettings> 
</configuration> 

다음은 서비스 응용 프로그램 코드입니다. 고맙습니다.

답변

0

나중에 이벤트 로그를 확인하고 문제가 바인딩 시간과 관련이 있으며 00:10:00으로 변경되었지만 작동하는 것으로 보입니다. 그러나 이번에는 새로운 오류가 발생하여 관련이 없습니다. 이 질문.

1

모든 서비스 주소가 서비스 및 클라이언트 구성 파일 모두에서 localhost로 설정되어있는 것처럼 보입니다. Localhost는 항상 프로그램이 실행중인 컴퓨터를 나타냅니다.

서비스에 올바른 컴퓨터 이름을 사용하고 클라이언트에서이를 참조해야합니다.

예를 들어, 귀하의 서비스가 다음 주소 (예 : myservicebox : 8732)로 네트워크상의 컴퓨터에서 호스팅된다고 가정 해보십시오. 서비스의 config 파일은 다음과 같습니다 당신은 다음 서비스를 이용하고자하는 클라이언트 (들)에 net.tcp://myservicebox:8732/WCFLogin를 참조 할 것

<service name="WorkMateWCF.WCFLogin"> 
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="" 
      contract="WorkMateWCF.IWCFLogin"> 
    <identity> 
     <dns value="myservicebox" /> 
    </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" 
      contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="net.tcp://myservicbox:8732/WCFLogin" /> 
     </baseAddresses> 
    </host> 
    </service> 

.

또한 게시 된 설정 파일을 기반으로하는 서비스는 지정된 바인딩에 대한 기본값을 사용하므로 다른 값 (예 : 더 큰 메시지 크기 등)이 필요할 경우 문제가 발생할 수 있습니다.

클라이언트 구성은 bindingConfiguration 속성을 통해 클라이언트 끝점에 할당 할 때 설정 한 바인딩을 사용합니다.

어쨌든 클라이언트에서 기본값을 사용하고있는 것처럼 보이지만 문제는 아닐 수도 있습니다.

+0

감사합니다. 나는 이것을 어떤 방식 으로든 주최해야만 했는가? Windows 서비스 프로젝트를 사용하여 설치했습니다. 당신의 응답을 기다리는. 감사합니다. – surpavan

+0

Windows 서비스에서 WCF 서비스를 호스팅하는 것이 좋습니다. 모든 요구 사항과 요구 사항에 따라 달라집니다 (IIS/WAS에서 자체 호스트 및 호스트 가능). 나는 일반적으로 IIS를 사용하지만 Windows 서비스에서 호스팅되는 하나의 서비스를 가지고 있습니다. – Tim

+0

그러나 localhost의 이름을 pc 이름으로 변경하여 시도했지만 현재는 앱이 자체 PC에서도 작동하지 않습니다. 간단한 교체로 어떤 것이 잘못 되었습니까? 내 프로그램은 인터넷이 아닌 10-15 PC 전용 소규모 네트워크 용입니다. 기대하고 있습니다. – surpavan

관련 문제