2009-08-12 4 views
17

WCF 서비스와 통신하는 클라이언트 콘솔 앱이 있는데 다음 오류가 발생합니다. "서버가 의미있는 응답을 제공하지 않았습니다. 계약 불일치, 세션 종료 또는 내부 서버 오류. "WCF 계약 불일치 문제

계약 불일치로 인한 것 같지만 그 이유를 알 수 없습니다. 이 서비스는 자체적으로 잘 실행되며 가장 부분 코드를 추가 할 때까지 두 부분이 함께 작동합니다.

누구나 잘못된 것을 볼 수 있습니까? WCF 서비스의 구성 파일을 여기

NetTcpBinding binding = new NetTcpBinding(); 
binding.Security.Mode = SecurityMode.Message; 
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows; 

EndpointAddress endPoint = new EndpointAddress(new Uri("net.tcp://serverName:9990/TestService1")); 
ChannelFactory<IService1> channel = new ChannelFactory<IService1>(binding, endPoint); 
channel.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; 
IService1 service = channel.CreateChannel(); 

을 그리고있다 : 여기

클라이언트, 모든 코드에서 이루어집니다

<configuration> 
    <system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="MyBinding"> 
      <security mode="Message"> 
      <transport clientCredentialType="Windows"/> 
      <message clientCredentialType="Windows" /> 
      </security> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WCFTest.ConsoleHost2.Service1Behavior"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <serviceAuthorization impersonateCallerForAllOperations="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service behaviorConfiguration="WCFTest.ConsoleHost2.Service1Behavior" 
      name="WCFTest.ConsoleHost2.Service1"> 
     <endpoint address="" binding="wsHttpBinding" contract="WCFTest.ConsoleHost2.IService1"> 
      <identity> 
      <dns value="" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <endpoint binding="netTcpBinding" bindingConfiguration="MyBinding" 
      contract="WCFTest.ConsoleHost2.IService1" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://serverName:9999/TestService1/" /> 
      <add baseAddress="net.tcp://serverName:9990/TestService1/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    </system.serviceModel> 
</configuration> 

답변

1

좋아, 난 그냥 클라이언트 그것을 있도록 변경했습니다 코드 대신 설정 파일을 사용하면 같은 오류가 발생합니다!

코드 : 여기

ServiceReference1.Service1Client client = new WCFTest.ConsoleClient.ServiceReference1.Service1Client("NetTcpBinding_IService1");  
client.PrintMessage("Hello!"); 

는이 계약 불일치 오류

<configuration> 
    <system.serviceModel> 
     <bindings> 
      <netTcpBinding> 
       <binding name="NetTcpBinding_IService1" 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="Message"> 
         <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> 
         <message clientCredentialType="Windows" /> 
        </security> 
       </binding> 
      </netTcpBinding> 
      <wsHttpBinding> 
       <binding name="WSHttpBinding_IService1" 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" 
        allowCookies="false"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <reliableSession ordered="true" inactivityTimeout="00:10:00" 
         enabled="false" /> 
        <security mode="Message"> 
         <transport clientCredentialType="Windows" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="Windows" negotiateServiceCredential="true" 
          algorithmSuite="Default" establishSecurityContext="true" /> 
        </security> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://servername:9999/TestService1/" binding="wsHttpBinding" 
       bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1" 
       name="WSHttpBinding_IService1"> 
       <identity> 
        <dns value="&#xD;&#xA;   " /> 
       </identity> 
      </endpoint> 
      <endpoint address="net.tcp://serverName:9990/TestService1/" binding="netTcpBinding" 
       bindingConfiguration="NetTcpBinding_IService1" contract="ServiceReference1.IService1" 
       name="NetTcpBinding_IService1"> 
       <identity> 
        <userPrincipalName value="MyUserPrincipalName " /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 
+0

예, 아마 다음은

내가 문제를 해결 도움이 코드 조각입니다 인터넷 서버 오류." –

33
하지 않을 수도 있습니다 나의 생각을하게 갓 서비스에서 생성 된 클라이언트의 설정 파일입니다 ...

다른 원인은 :

  • 는 OBJ 직렬화하려고 기본 생성자없이 요법.
  • 다른 종류의 비 직렬화 가능 객체 (예 : 예외)를 직렬화하려고합니다. 항목이 일련 화되지 않도록하려면 필드 또는 속성에 [IgnoreDataMember] 속성을 적용하십시오.
  • 열거 형 필드가 유효한 값으로 설정되어 있는지 (또는 null을 허용하는지) 확인하십시오. 경우에 따라 열거 형에 0 값을 추가해야 할 수도 있습니다. (이 점에 대한 자세한 내용은 확실하지 않음). 어떤 시험에

적어도 심각한 오류 또는 예외

  • Configure WCF tracing. 더 이상 추적 할 수 없으면 파일 크기를 조심하십시오. 이것은 많은 경우에 매우 유용한 정보를 줄 것입니다.

    그냥 서버 ON 당신의 web.config<configuration>에 따라 본을 추가합니다. 존재하지 않는 경우 log 디렉토리를 작성하십시오.

    <system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="Error, Critical" propagateActivity="true"> <listeners> <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "c:\log\WCF_Errors.svclog" /> </listeners> </source> </sources> </system.diagnostics> 

    은 SVC는 파일은 실제로 오류없이 브라우저에서 반드시 올 것입니다 있는지 확인합니다. 이것은 당신에게 '첫 기회'를 줄 것입니다. 예를 들어 직렬화 할 수없는 객체가있는 경우 아래에이 메시지가 표시됩니다. 직렬화 할 수없는 것을 명확하게 알려줍니다. 'mex'엔드 포인트를 사용하도록 설정하고 브라우저에서 .svc 파일을 가져 오십시오.나를 위해

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior contract: http://tempuri.org/:IOrderPipelineService ----> System.Runtime.Serialization.InvalidDataContractException: Type 'RR.MVCServices.PipelineStepResponse' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.

+2

+1 감사합니다 -이 오류로 맞았습니다, 당신의 대답을 발견하고 문제가 비트 마스크 열거로 인한 것으로 밝혀졌습니다 : 두 개 이상의 비트가 설정되어 있으므로 (따라서 하나의 열거 형과 일치하는) 직렬화 실패! –

+0

비슷한 문제가 있습니다. 서비스는 괜찮습니다. 한 명의 고객이 일하고 있습니다. 하지만 두 번째 클라이언트가 작동하지 않습니다 : http://stackoverflow.com/questions/12420314/one-wcf-service-two-clients-one-client-does-not-work – Lijo

8

,이 오류 메시지는 기본적으로 내 Web.config의 서비스 동작이 낮은 메시지 제한이 있기 때문에 발생하므로 WCF 말할 돌아 왔을 때 200000 바이트 내 한계는 응답이 64000 바이트이었다이었다 잘라 버려서 "... 의미있는 답장"을받지 못합니다. 그것은 의미가 있으며, 그냥 잘려서 파싱 할 수 없습니다.

<system.serviceModel> 
<behaviors> 
<serviceBehaviors> 
<behavior name="YourNameSpace.DataServiceBehavior"> 
<serviceMetadata httpGetEnabled="true"/> 
<serviceDebug includeExceptionDetailInFaults="false"/> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
     <serviceTimeouts transactionTimeout="05:05:00" /> 
     <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" 
     maxConcurrentInstances="2147483647" /> 
</behavior> 
</serviceBehaviors> 
</behaviors> 

maxItemsInObjectGraph 값이 가장 중요하다

나는 문제를 해결 내 Web.config의 변화를 붙여거야!
누구에게 도움이되기를 바랍니다.

+0

나는 비슷한 문제가있어. 서비스는 괜찮습니다. 한 명의 고객이 일하고 있습니다. 하지만 두 번째 클라이언트가 작동하지 않습니다 : http://stackoverflow.com/questions/12420314/one-wcf-service-two-clients-one-client-does-not-work – Lijo

2

나는 비슷한 문제가 발생했다를 던질 것이다 WCF에서 동일한 이름과 매개 변수를 두 가지 방법이있는 경우. 이 작업을 2 시간 동안 진행하면서 마음으로 온라인 답을 찾으려는 끝에 System.Runtime.Serialization.DataContractSerializer를 사용하여 서버 측에서 반환 값/개체를 직렬화 및 비 직렬화하는 방법을 따르기로 결심했습니다. 열거 형 중 하나에 EnumMember 특성을 추가하지 못했습니다.

비슷한 문제가 발생할 수 있습니다. "....., 조기 세션 종료 또는 - 오류 메시지는 두 개 더 가능 casuse을 제공

 var dataContractSerializer = new System.Runtime.Serialization.DataContractSerializer(typeof(MyObject)); 
     byte[] serializedBytes; 
     using (System.IO.MemoryStream mem1 = new System.IO.MemoryStream()) 
     { 
      dataContractSerializer.WriteObject(mem1, results); 
      serializedBytes = mem1.ToArray(); 
     } 

     MyObject deserializedResult; 
     using (System.IO.MemoryStream mem2 = new System.IO.MemoryStream(serializedBytes)) 
     { 
      deserializedResult = (MyObject)dataContractSerializer.ReadObject(mem2); 
     } 
+0

이것은 로컬 디버깅을위한 가장 빠른 옵션입니다. 감사합니다. ! –

관련 문제