问题
after a server call my client catches an exception with the following message
"The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error."
Also, note I tried the configuration in WCF "The server did not provide a meaningful reply" but still didn't work.
Please note, that I debug the service to the end, and the data is successfully populated but at the client end when the data is supposed to appear it just crashes with the mentioned exception.
Any help appreciated.
回答1:
I figured out the reason behind this that the proxy was wrongly generated for an enum type, it was generated as a string so it failed and gave me out that exception
回答2:
If someone else comes across this same exception, with the same behavior of debugging to the end in the server, but getting the exception on the return to the client, another possible cause is an uninitialized enum in the return data contract where the enum has explicit values, but no explicit zero value.
[ServiceContract]
public interfact IMyService
{
[OperationContract]
MyResult DoSomething();
}
[DataContract]
public class MyResult
{
[DataMember]
public OperationStatus Status {get; set;}
[DataMember]
public string ErrorText {get; set;}
}
[DataContract]
public enum Operation Status
{
[EnumMember]
Success = 1,
[EnumMember]
Failure = 2
}
public class MyService : IMyService
{
public MyResult DoSomething()
{
var result = new MyResult();
// ... do work, but don't set any properties on result ...
return result;
}
}
The reason the error happens in this scenario is that result.Status defaults to zero, but the data contract does not provide any means to serialize it, since it is not one of the explicitly defined enum values.
The solution (assuming you really do need this enum with explicit integer values) is to either set the enum value in the return object, or provide a default (zero) value.
[DataContract]
public enum Operation Status
{
[EnumMember]
Unknown = 0,
[EnumMember]
Success = 1,
[EnumMember]
Failure = 2
}
--Bill
回答3:
if your web service return a DataTable, it must have TableName; look at https://stackoverflow.com/a/5894732/775811
回答4:
The cause of this error for me was a missing FaultContractAttribute(typeof(FaultModel)) on the Server function interface (The one marked with OperationContract attribute).
When the FaultException< FaultModel >() was thrown on the server side the client side was throwing - CommunicationException: "The server did not provide a meaningful reply this might be caused by a contract mismatch, a premature session shutdown or an internal server error.".
Hope will help someone.
回答5:
This happened to me on a new system (Windows 10) after trying to call a Windows Workflow service. Other WCF service calls were working, but trying to call the workflow activity (a xamlx WF4 service) received this error.
Trying to browse to the service.xamlx
file resulted in a blank screen. That eventually led me to this other answer (the IIS8 specific answer), which is to add the HTTP Activation feature under IIS Services:
WCF on IIS8; *.svc handler mapping doesn't work
来源:https://stackoverflow.com/questions/5793504/wcf-catches-exception-the-server-did-not-provide-a-meaningful-reply