2009-08-12 30 views
17

Tôi có một ứng dụng bàn điều khiển khách hàng nói chuyện với dịch vụ WCF và tôi nhận được lỗi sau: "Máy chủ không cung cấp trả lời có ý nghĩa, điều này có thể là do không khớp hợp đồng, tắt phiên trước hoặc một lỗi máy chủ nội bộ. "Vấn đề không khớp của hợp đồng WCF

Tôi nghĩ rằng đó là do hợp đồng không khớp nhưng tôi không thể hiểu tại sao. Dịch vụ này chỉ chạy tốt và 2 phần đã hoạt động cùng nhau cho đến khi tôi thêm mã mạo danh.

Có ai có thể thấy điều gì sai không?

Đây là khách hàng, tất cả được thực hiện trong mã:

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(); 

Và đây là tập tin cấu hình của dịch vụ WCF:

<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> 

Trả lời

1

Ok, tôi vừa thay đổi của khách hàng vì thế nó sử dụng một tập tin cấu hình thay vì mã và tôi nhận được cùng một lỗi!

Code:

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

Đây là tập tin cấu hình của khách hàng, vừa mới được tạo ra từ các dịch vụ ... mà làm cho suy nghĩ của tôi rằng nó có thể không phải là một lỗi hợp đồng không phù hợp

<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

Vâng, có lẽ không - được thông báo lỗi cũng cung cấp thêm hai casuse càng tốt:" ....., một phiên shutdown non hoặc một lỗi máy chủ nội bộ. " –

33

Các nguyên nhân khác có thể:

  • Đang cố gắng để serialize một obj ect mà không có một constructor mặc định.
  • Cố gắng sắp xếp một số loại đối tượng không thể tuần tự hóa khác (chẳng hạn như Ngoại lệ). Để ngăn không cho mục đó được áp dụng theo thứ tự [IgnoreDataMember] thuộc tính vào trường hoặc thuộc tính.
  • Kiểm tra các trường enum của bạn để đảm bảo chúng được đặt thành giá trị hợp lệ (hoặc không có giá trị). Bạn có thể cần thêm giá trị 0 vào enum trong một số trường hợp. (không chắc chắn về chi tiết tốt của điểm này).

gì để kiểm tra:

  • Configure WCF tracing lỗi ít nhất quan trọng hoặc trường hợp ngoại lệ. Hãy cẩn thận để xem các tập tin nếu bạn kích hoạt bất kỳ dấu vết hơn nữa. Điều này sẽ cung cấp một số thông tin rất hữu ích trong nhiều trường hợp.

    Chỉ cần thêm số này dưới <configuration> trong số web.configTRÊN MÁY CHỦ. Tạo thư mục log nếu nó không tồn tại.

<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> 
  • Hãy chắc chắn rằng các tập tin .svc sẽ thực sự đưa ra trong một trình duyệt mà không có lỗi. Điều này sẽ cung cấp cho bạn một số trợ giúp 'cơ hội đầu tiên'. Ví dụ nếu bạn có một đối tượng không serializable bạn sẽ nhận được thông báo này dưới đây. Lưu ý rằng nó rõ ràng cho bạn biết những gì không thể được tuần tự hóa. Đảm bảo bạn đã bật điểm cuối 'mex' và hiển thị tệp .svc trong trình duyệt của bạn.

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 Cảm ơn - Tôi đã gặp lỗi này, tôi đã tìm thấy câu trả lời của bạn và hóa ra vấn đề là do đếm bitmask: khi bạn có nhiều hơn một bit (và do đó không có giá trị enum nào phù hợp) thất bại! –

+0

Tôi gặp vấn đề tương tự. Dịch vụ là tốt. Một khách hàng đang làm việc; nhưng khách hàng thứ hai không hoạt động: http://stackoverflow.com/questions/12420314/one-wcf-service-two-clients-one-client-does-not-work – Lijo

8

Đối với tôi, thông báo lỗi này đã được ném bởi vì tôi lại hành vi Dịch vụ web.config theo mặc định có một giới hạn nhắn thấp, vì vậy khi WCF trở nói 200000 byte và giới hạn của tôi là 64000 bytes phản ứng là cắt ngắn và do đó bạn nhận được câu trả lời "... không có ý nghĩa". Nó có ý nghĩa, nó chỉ bị cắt ngắn và không thể được phân tích cú pháp.

tôi sẽ dán thay đổi web.config của tôi mà cố định vấn đề:

<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> 

Giá trị maxItemsInObjectGraph là quan trọng nhất!
Tôi hy vọng điều này sẽ giúp mọi người.

+0

Tôi gặp vấn đề tương tự. Dịch vụ là tốt. Một khách hàng đang làm việc; nhưng ứng dụng khách thứ hai không hoạt động: http://stackoverflow.com/questions/12420314/one-wcf-service-two-clients-one-client-does-not-work – Lijo

0

Nếu bạn có hai phương pháp có cùng tên và thông số trong WCF của bạn, nó sẽ ném lỗi này

2

Tôi gặp sự cố tương tự. Sau khi dành một tâm trí trong 2 giờ và cố gắng tìm câu trả lời trực tuyến, tôi quyết định làm theo cách tiếp cận để tính toán và deserialize giá trị trả về/đối tượng ở phía máy chủ bằng cách sử dụng System.Runtime.Serialization.DataContractSerializer và cuối cùng thấy rằng tôi đã bỏ lỡ thêm thuộc tính EnumMember vào một trong các Enums.

Bạn có thể đang gặp phải sự cố tương tự.

Dưới đây là đoạn mã đó đã giúp tôi giải quyết vấn đề:

 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

Đây là tùy chọn nhanh nhất để gỡ lỗi cục bộ, cảm ơn ! –

Các vấn đề liên quan