WCF An error occurred while receiving the HTTP response

▼魔方 西西 提交于 2020-01-05 12:08:59

问题


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

Here's the PaymentData class:

[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; }
}

... and the enums defined in the PaymentData class

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

Here's the error from the WCFTest Client:

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.

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)

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

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)

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)

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)


回答1:


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



来源:https://stackoverflow.com/questions/15342117/wcf-an-error-occurred-while-receiving-the-http-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!