WCF收到HTTP响应时发生错误 [英] WCF An error occurred while receiving the HTTP response

查看:128
本文介绍了WCF收到HTTP响应时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的WCF服务应该返回的内容。当我从ResponseModel中命令PaymentData并在该类中添加其他DataMember时。

Here's what my WCF service should be returning. When I command PaymentData out of ResponseModel and add other DataMembers in that class it works.

[DataContract]
public class ResponseModel
{
    [DataMember]
    public PaymentData PaymentData { get; set; }
}

以下是 PaymentData 类:

[DataContract]
public class PaymentData
{
    [DataMember]
    public PaymentType PaymentType { get; set; }
    [DataMember]
    public string CardNumber { get; set; }
    [DataMember]
    public DateTime ExpirationDate { get; set; }
    /// <summary>
    /// If true, then the CardNumber property will contain the token
    /// </summary>
    [DataMember]
    public bool IsCardNumberTokenized { get; set; }
    /// <summary>
    /// Number on back of credit cards. This value CANNOT be stored anywhere
    /// </summary>
    [DataMember]
    public string CardSecurityValue { get; set; }
    [DataMember]
    public CardSecurityPresence CardSecurityPresence { get; set; }
}

...以及中定义的枚举PaymentData

[DataContract(Name = "CardSecurityPresenceEnum")]
public enum CardSecurityPresence
{
    [EnumMember(Value = "1")]
    IsPresent = 1,
    [EnumMember(Value = "2")]
    Illegible = 2,
    [EnumMember(Value = "9")]
    NoCodeOnCard = 9,
    [EnumMember(Value = " ")]
    NotSent
}

[DataContract(Name = "PaymentTypeEnum")]
public enum PaymentType
{
    [EnumMember]
    Visa = CMPWSApiService.TransactionMop.VI,
    [EnumMember]
    MasterCard = CMPWSApiService.TransactionMop.MC,
    [EnumMember]
    AmericanExpress = CMPWSApiService.TransactionMop.AX,
    [EnumMember]
    Discover = CMPWSApiService.TransactionMop.DI,
    [EnumMember]
    PayPal = CMPWSApiService.TransactionMop.PP,
    [EnumMember]
    BillMeLater = CMPWSApiService.TransactionMop.BL
}

序列化不是我的变量名具有

Does the serialization not like that my variable names have the same names as their classes?

这是WCFTest Client的错误:

Here's the error from the WCFTest Client:


收到对
的HTTP响应[服务URL省略]时发生错误。该
可能是由于服务端点绑定未使用HTTP
协议引起的。这也可能是由于服务器终止了
的HTTP请求上下文(可能是由于服务关闭)。有关更多详细信息,请参见
服务器日志。

An error occurred while receiving the HTTP response to [service url omitted]. 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.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException
webException,HttpWebRequest请求,HttpAbortReason abortReason)在
处的
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan
timeout)在
System.ServiceModel处。 Channels.RequestChannel.Request(消息消息,
TimeSpan超时)位于
System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息
消息,TimeSpan超时)位于
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操作)在
处System.ServiceModel.C hannels.ServiceChannelProxy.Invoke(IMessage
消息)

Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.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)

在[0]处抛出异常:
System.Runtime.Remoting.Proxies.RealProxy。 HandleReturnMessage(IMessage
reqMsg,IMessage retMsg)at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData,Int32类型)位于ICreditCardService.TestAuth(),位于
CreditCardServiceClient.TestAuth()

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 ICreditCardService.TestAuth() at CreditCardServiceClient.TestAuth()

内部异常:基础连接已关闭:收到意外的
错误。在
处System.Net.HttpWebRequest.GetResponse()在
处System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan
超时)

Inner Exception: The underlying connection was closed: An unexpected error occurred on a receive. at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

内部异常:无法从传输连接中读取数据:
现有连接已由远程主机强行关闭。在System.Net.PooledStream.Read(Byte []缓冲区,Int32
偏移处,在
处System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,
Int32大小) ,Int32大小)为
。System.Net.Connection.SyncRead(HttpWebRequest请求,布尔值
userRetrievedStream,布尔值ProbeRead)

Inner Exception: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. 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)

内部异常:现有System.Net.Sockets.Socket.Receive(Byte []缓冲区,
Int32偏移量,Int32大小,SocketFlags socketFlags)在
System.Net上的
远程主机强制关闭了连接。 Sockets.NetworkStream.Read(Byte [] buffer,Int32偏移量,
Int32大小)

Inner Exception: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)


推荐答案

CardSecurityPresenceEnum 中,我有一个名为 NotSent 的枚举成员,该成员没有初始化为值。由于某种原因,这使事情挂起来。

In CardSecurityPresenceEnum I had a enum member called NotSent that was not initialized to a value. For some reason that was hanging things up.

这篇关于WCF收到HTTP响应时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆