Reputation: 9684
I have started recieving this error in my WCF service for reasons I cannot comprehend: The underlying connection was closed: The connection was closed unexpectedly.
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 IPublicService.GetProduct(String barcode)
at PublicServiceClient.GetProduct(String barcode)Inner Exception: The underlying connection was closed: The connection was closed unexpectedly. at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
Here is the service method:
public Product GetProduct(string barcode)
{
DataContext Db = new DataContext();
var p = Db.Products.Find(barcode);
if (p == null)
return null;
return new Product()
{
ProductID = p.ProductID,
Name = p.Name,
Nutrition = p.Nutrition,
Allergen = p.Allergen,
Image = p.Image,
ManufacturerID = p.ManufacturerID,
ReviewIDs = p.ReviewIDs
};
}
Here is the Product data contract:
[DataContract]
public class Product
{
[Key]
[Required]
[DataMember]
public string ProductID { get; set; }
[Required]
[DataMember]
public string Name { get; set; }
[Required]
[DataMember]
public string Nutrition { get; set; }
[Required]
[DataMember]
public string Allergen { get; set; }
[Required]
[DataMember]
public string Image { get; set; }
[Required]
[DataMember]
public virtual Manufacturer ManufacturerID { get; set; }
[DataMember]
public virtual ICollection<Review> ReviewIDs { get; set; }
}
However if I change the service method to this:
public Product GetProduct(string barcode)
{
DataContext Db = new DataContext();
var p = Db.Products.Find(barcode);
if (p == null)
return null;
//return new Product()
//{
// ProductID = p.ProductID,
// Name = p.Name,
// Nutrition = p.Nutrition,
// Allergen = p.Allergen,
// Image = p.Image,
// ManufacturerID = p.ManufacturerID,
// ReviewIDs = p.ReviewIDs
//};
return new Product();
}
No exception is thrown and it returns and empty product, so I am not sure what is causing the ambiguous exception I am getting, can anyone shed some light on this issue?
Upvotes: 0
Views: 1612
Reputation: 39085
In general, you should use the Svctraceviewer.exe provided by Microsoft for debugging the WCF pluming. You should run a trace on the service side.
Upvotes: 1
Reputation: 19020
Unfortunately the WCF exceptions are not always very helpful but it is likely that you run into some of the inbuilt WCF limits (which are tunable). The default MaxReceivedMessageSize
is 64kb and the default maximum string length is 8kb I think. Try increasing those limits should fix your problems.
Upvotes: 1