nel*_*eus 2 .net wcf enums datacontract
我的问题与此类似,但有一个有趣的区别。我已经明确定义了所有值,但仍然无法正常工作。如果可能,我也尽量避免使用合同属性。
所以这一切看起来像什么。我定义了一个具有枚举类型的属性的合同。枚举是
public enum ErrorCodes
{
GeneralError = 1,
ValidationError = 2,
AuthenticationError = 3
}
Run Code Online (Sandbox Code Playgroud)
然后客户端因错误而失败:
System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to http://localhost/MyTestAppService/SomeService.svc/soap. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MyTestApp.ISomeService.TestMethod(TestRequest request)
Run Code Online (Sandbox Code Playgroud)
当我删除所有显式值时,它将起作用:
public enum ErrorCodes
{
GeneralError,
ValidationError,
AuthenticationError
}
Run Code Online (Sandbox Code Playgroud)
我终于找到了一个非常简单的解决方案。文档中没有提到它似乎很奇怪。
枚举只需要具有默认值,一切就可以像超级按钮一样工作!不知道这是一个不错的错误还是未记录的功能。
public enum ErrorCodes
{
Default = 0, // without this member WCF fails
GeneralError = 1,
ValidationError = 2,
AuthenticationError = 3
}
Run Code Online (Sandbox Code Playgroud)
我是怎么想到的?我只是尝试了其他枚举,它甚至具有显式的值也可以工作,所幸的是,它具有默认值。
| 归档时间: |
|
| 查看次数: |
650 次 |
| 最近记录: |