WCF with Entity Framework Error Part II - wcf

Newbie, please bear with me as I just started yesterday with WCF.
I am using Northwind for the data and only added Customers, Orders, Order Details and Products to the model, so nothing fancy.
When I launch the application and invoke Test, and set a breakpoint, the value for products is there and it completes without error. If I then try to invoke GetMaxQuantityByOrderID(10248), I get the error listed at bottom. Why would Test() work and the same method WITHIN Test() NOT work? I even added another (Test1(), exact same as Test except it returns string: x.ProductName, which correctly displays Queso Cabrales). It seems odd that a method that is being called within another works, but calling it directly causes an exception.
Another issue I have is that the IEnumerable GetOrders() works only if I add .ToList(). Without it (or with .AsEnumerable()), I get an error (The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.), even though lazy loading is set to False. What is the logic behind this?
IServiceTest.cs
using System.Collections.Generic;
using System.ServiceModel;
namespace WcfTestServiceLibrary
{
[ServiceContract]
public interface IServiceTest
{
[OperationContract]
IEnumerable<Orders> GetOrders();
[OperationContract]
IEnumerable<Customers> GetCustomers();
[OperationContract]
Customers GetCustomerByID(string customerID);
[OperationContract]
Orders GetOrderByID(int id);
[OperationContract]
IEnumerable<Order_Details> GetOrderDetailsByOrderID(int id);
[OperationContract]
Order_Details GetMaxQuantityByOrderID(int id);
[OperationContract]
void Test();
}
}
ServiceTest.cs
using System.Collections.Generic;
using System.Linq;
namespace WcfTestServiceLibrary
{
public class ServiceTest : IServiceTest
{
public IEnumerable<Orders> GetOrders()
{
using (var ctx = new NWEntities())
{
return (from o in ctx.Orders.Include("Order_Details.Products").Include("Customers")
select o).ToList();
}
}
public IEnumerable<Customers> GetCustomers()
{
using (var ctx = new NWEntities())
{
return (from c in ctx.Customers
select c);
}
}
public Customers GetCustomerByID(string customerID)
{
return (from c in GetCustomers()
where c.CustomerID == customerID
select c).FirstOrDefault();
}
public Orders GetOrderByID(int id)
{
IEnumerable<Orders> orders = GetOrders();
return (from o in orders
where o.OrderID == id
select o).FirstOrDefault();
}
public IEnumerable<Order_Details> GetOrderDetailsByOrderID(int id)
{
return GetOrderByID(id).Order_Details;
}
public Order_Details GetMaxQuantityByOrderID(int id)
{
Orders order = GetOrderByID(id);
return order == null ? null : order.Order_Details.OrderByDescending(x => x.Quantity).FirstOrDefault();
}
public void Test()
{
const int orderID = 10248;
var oq = GetMaxQuantityByOrderID(orderID);
var x = oq.Products;
}
}
}
Error:
An error occurred while receiving the HTTP response to http://localhost:8732/Design_Time_Addresses/WcfTestServiceLibrary/Service1/. 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.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.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 IServiceTest.GetMaxQuantityByOrderID(Int32 id)
at ServiceTestClient.GetMaxQuantityByOrderID(Int32 id)
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)

I had a very similar issue as you did. I found out that the Entity Framework proxy that wraps around your POCO classes is by default serialized by the WCF serializer, which cannot be deserialized on the client side since the client is not aware of the EF proxy wrapper. There were two solutions that I found. The first is to set ContextOptions.ProxyCreationEnabled to false. This prevents the EF from creating proxies for your POCO objects. The second was to instruct the WCF DataContractSerializer on the server side to use the ProxyDataContractResolver to serialize as just the POCO.
The second option can be found at http://msdn.microsoft.com/en-us/library/ee705457.aspx. Since I have just discovered these solutions I can't say which I would recommend as a general practice, although I lean to the latter, since the EF queries may be re-used by other callers from time to time that may want the objects returned with the appropriate EF proxies. Anyhow I know that's late to this question, but I hope that helps others who come across this issue.

Its the .Inculde in your LINQ-Statement.
I believe the reason for this is the basicaly resulting infinite datastructure pointing to and from "one" side to the "many" side of your relationship.
This you can observe by unfolding your datastructure, setting a breakpoint at the result of your .Include query statement in the debugger...
Observation:
Orders --> many Products, each product--> Order--> many Products and so forth
I guess wcf runns into that and gets cought up in that.
To break this chain of, you can simply avoid the pointing back in your data transfer object
by adding the ignoreDataMember Attribute
In the Many-Side of your relationship... In your case the Product....
[IgnoreDataMember]
public Order OrderFatherElement { get; set; }
This way WCF will stop the serializingattempt when reaching that childnode
#microsoft.... some potential for a fix?
Greets,
Kieredin Garbaa

For the first issue try to turn on WCF tracing on your service. Second issue with IEnumerable is caused by deffered execution. Btw. do you understand difference between IQueryable<T> and IEnumerable<T>? Do you know that your GetOrders method loads all Orders, related Customers and Products into memory? Even if you want to select single order you still load all of them in the service.
Edit:
WCF tracing will show you what happend during service or client execution - it traces WCF internals and it is essential tool for WCF development. Tutorial on WCF tracing and trace viewer.
IQueryable builds expression tree which is compiled into database query so you can't execute that query (deffered execution) outside context scope (context is responsible for database connection). You have to rewrite your methods. In your case each method has to create complete query and execute that query inside context scope. Execution of query is performed by selecting single record (like FirstOrDefault()) or by converting to list.

Related

How do I Provision a Transport Handler for IoTHub?

I am trying to connect to IoTHub to provision my device.
I am in a Blazor WASM app.
I have created the Security Provider Symmetric Key via:
SecurityProvider symmetricKeyProvider = new SecurityProviderSymmetricKey(parameters.DeviceId, parameters.DeviceSymmetricKey, null);
However my next line I call:
ProvisioningTransportHandler mqttTransportHandler = new ProvisioningTransportHandlerMqtt(TransportFallbackType.TcpOnly);
I have tried it with both the TcpOnly fallback along with not passing in any fallback and both give me the same error. The exception is:
Error provisioning device: The type initializer for 'Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningTransportHandlerMqtt' threw an exception.
System.TypeInitializationException: The type initializer for 'Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningTransportHandlerMqtt' threw an exception.
---> System.InvalidOperationException: failed to create a child event loop.
---> System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Threading.Thread.Start()
at DotNetty.Common.Concurrency.SingleThreadEventExecutor..ctor(IEventExecutorGroup parent, String threadName, TimeSpan breakoutInterval, IQueue`1 taskQueue)
at DotNetty.Common.Concurrency.SingleThreadEventExecutor..ctor(IEventExecutorGroup parent, String threadName, TimeSpan breakoutInterval)
at DotNetty.Transport.Channels.SingleThreadEventLoop..ctor(IEventLoopGroup parent, String threadName, TimeSpan breakoutInterval)
at DotNetty.Transport.Channels.SingleThreadEventLoop..ctor(IEventLoopGroup parent)
at DotNetty.Transport.Channels.MultithreadEventLoopGroup.<>c.<.cctor>b__24_0(IEventLoopGroup group)
at DotNetty.Transport.Channels.MultithreadEventLoopGroup..ctor(Func`2 eventLoopFactory, Int32 eventLoopCount)
--- End of inner exception stack trace ---
at DotNetty.Transport.Channels.MultithreadEventLoopGroup..ctor(Func`2 eventLoopFactory, Int32 eventLoopCount)
at DotNetty.Transport.Channels.MultithreadEventLoopGroup..ctor()
at Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningTransportHandlerMqtt..cctor()

Json Errors in raven 3.5 client

Periodically we receive the following error when saving to a Raven Database. The client and database are v3.5. The solution thus far has been to restart the servers and after that things appear to settle down. The user can go to a different server and can go back into the site and retrieved what was saved. However when we see 1 error like this on a server the server starts to report 100's of them. We cannot reproduce this in QA. So I am leaning towards load or our Raven Sessions are not being closed properly.
Calling the Raven OpenSessionAsync() as the point of creating the class
IAsyncDocumentSession
public async Task<bool> SaveChangesAsync()
{
using (_session)
{
await _session.SaveChangesAsync();
}
return true;
}
This is the area in our code that starts the error when saving should we also be doing something more?
Message: Token PropertyName in state Property would result in an invalid JSON object. Path ''.
Raven.Imports.Newtonsoft.Json.JsonWriter.AutoComplete(JsonToken tokenBeingWritten) in C:\Builds\RavenDB-Stable-3.5\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\JsonWriter.cs:779
Raven.Json.Linq.RavenJTokenWriter.WritePropertyName(String name) in C:\Builds\RavenDB-Stable-3.5\Raven.Abstractions\Json\Linq\RavenJTokenWriter.cs:51
Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) in C:\Builds\RavenDB-Stable-3.5\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:428
Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) in C:\Builds\RavenDB-Stable-3.5\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:101
Raven.Imports.Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType) in C:\Builds\RavenDB-Stable-3.5\Imports\Newtonsoft.Json\Src\Newtonsoft.Json\JsonSerializer.cs:949
Raven.Json.Linq.RavenJToken.FromObjectInternal(Object o, JsonSerializer jsonSerializer) in C:\Builds\RavenDB-Stable-3.5\Raven.Abstractions\Json\Linq\RavenJToken.cs:91
Raven.Json.Linq.RavenJObject.FromObject(Object o, JsonSerializer jsonSerializer) in C:\Builds\RavenDB-Stable-3.5\Raven.Abstractions\Json\Linq\RavenJObject.cs:174
Raven.Client.Document.EntityToJson.GetObjectAsJson(Object entity) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\EntityToJson.cs:72
Raven.Client.Document.EntityToJson.ConvertEntityToJson(String key, Object entity, RavenJObject metadata) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\EntityToJson.cs:44
Raven.Client.Document.InMemoryDocumentSessionOperations.EntityChanged(Object entity, DocumentMetadata documentMetadata, IDictionary2 changes) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\InMemoryDocumentSessionOperations.cs:1218
Raven.Client.Document.InMemoryDocumentSessionOperations.<PrepareForEntitiesPuts>b__110_0(KeyValuePair2 pair) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\InMemoryDocumentSessionOperations.cs:1025
System.Linq.Enumerable+WhereEnumerableIterator1.MoveNext():55
System.Linq.Buffer1..ctor(IEnumerable1 source):114
System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source):20
Raven.Client.Document.InMemoryDocumentSessionOperations.PrepareForEntitiesPuts(SaveChangesData result) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\InMemoryDocumentSessionOperations.cs:1025
Raven.Client.Document.InMemoryDocumentSessionOperations.PrepareForSaveChanges() in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\InMemoryDocumentSessionOperations.cs:986
Raven.Client.Document.Async.AsyncDocumentSession+d__73.MoveNext() in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\Async\AsyncDocumentSession.cs:928
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw():12
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task):46
ApplicantCenter.Services.ApplicationService+d__9.MoveNext() in d:\a\1\s\Project\Services\ApplicationService_Helpers.cs:207
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw():12
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task):46
ApplicantCenter.Controllers.ApplicationController+d__10.MoveNext() in d:\a\1\s\Project\Controllers\ApplicationController.cs:117
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw():12
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task):46
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass8_0.b__1(IAsyncResult asyncResult)
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters.b__11_0():19
System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters+<>c__DisplayClass11_1.b__2():134
System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters+<>c__DisplayClass11_1.b__2():134
System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters+<>c__DisplayClass11_1.b__2():134
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass3_6.b__3()
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass3_1.b__5(IAsyncResult asyncResult)
The problem here is that you are disposing the session that maybe used by others.
You put a global _session inside an using block, the _session resources will be disposed after the using block end, and other parts of code that are using the same global _session will become invalid.

Nhibernate queries fail itermitently

I'm having a really hard time nailing down a problem coming from NHibernate (3.3). The application serves some 150 req/s in a six node NLB cluster. The application behaves ok generally, but sometimes maybe 1-2 day the following error comes in the logs and all queries fail.
I'm using adonet.batch_size of 15 and MultipleActiveResultSets=True is set to true. All controllers inherit from AsyncController (this is an ASP.NET MVC 4 app), so session state is read only to maximize concurrency.
Initially, we had a lot of trouble NHibernate Session handling because the AbstractBatcher did a pretty poor job managing which readers were related to which connection. So, in a high load, readers would try to read from connections that were already closed. We solved this by defining manually the lifetime of a SQLConnection which stabilized things.
However, the following comes up often. I think it is a symptom of something really wrong with the session factory. At this point, I'm thinking about reinitializing the session factory when an unhandled exception of this type is thrown, but that's not nice. Does anyone have any insight to why this happens?
System.NotSupportedException: PartialEvaluationExceptionExpression
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitBinaryExpression(BinaryExpression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitBinaryExpression(BinaryExpression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitBinaryExpression(BinaryExpression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
at NHibernate.Linq.Visitors.QueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)
at Remotion.Linq.Clauses.WhereClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
at NHibernate.Linq.Visitors.QueryModelVisitor.GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, Boolean root)
at NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor sessionFactory)
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters)
at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow)
at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression)
at NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression expression, IQuery& query, NhLinqExpression& nhQuery)
at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)
at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
For those who may be facing this issue, I thought I'd give some insight of two years in production (thousands of users) of a fix that we put in place to address this issue.
In the base constructor we have something like this:
public MvcBaseController()
{
try
{
var currentRepositorySession = RepositorySession.Current;
dbConnection = new SqlConnection(currentRepositorySession.GetConnectionString());
dbConnection.Open();
session = currentRepositorySession.Create(false, dbConnection);
}
catch (Exception e)
{
LogDebug("Error was thrown: " + e.Message);
}
}
Binding the db connection to the NHibernate session forcefully is the only way to ensure that the AbstractBatcher doesn't close the session before all readers are done. On Dispose we have the following:
protected override void Dispose(bool disposing)
{
if (disposing)
{
try
{
if (session != null)
{
session.Dispose();
session = null;
}
}
catch (Exception ex)
{
LogDebug("Error was thrown: " + ex.Message);
}
try
{
if (dbConnection != null)
{
dbConnection.Close();
dbConnection.Dispose();
dbConnection = null;
}
}
catch (Exception ex)
{
LogDebug("Error was thrown: " + ex.Message);
}
}
base.Dispose(disposing);
}
This means that a connection is opened for every requests, which is fine. We had to increase SQL Server workers, but the system has been stable for two years now. The only time we've seen NHibernate session factory break is when there is a lot of data paged from the database, say 1 million records. Then the application pool overflows, and is orphaned. These were mostly code bugs and not related to the concurrency issues described in the question.

CommunicationException in processing Array function

I am testing interaction between server and client app on single desktop and having issue with processing Array. My interface looks next
<ServiceContract>
Public Interface IMyService
<OperationContract>
Function GetData() As Array
End Interface
Server side implementation, is next
Public Function GetData() As Array Implements IMyService.GetData
Return {1, 2, 3, 4, 5, 6, 7, 8}
End Function
Client side code, is next
Shared Function GetData() As Array
Dim channel As IMyService = Nothing
Try
channel = ChannelFactory(Of IMyService).CreateChannel(New NetTcpBinding, address)
Return channel.GetData()
Finally
If channel IsNot Nothing Then
CType(channel, IClientChannel).Close()
End If
End Try
End Function
I am getting next exception upon executing Return channel.GetData(), and I don't have an issue with other interface functions that returns simple types (double, integer, etc.). My server app is self hosting WCF service.
System.ServiceModel.CommunicationException occurred
HResult=-2146233087
Message=The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.9270000'.
Source=mscorlib
StackTrace:
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
InnerException: System.Net.Sockets.SocketException
ErrorCode=10054
HResult=-2147467259
Message=An existing connection was forcibly closed by the remote host
NativeErrorCode=10054
Source=System
StackTrace:
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
InnerException:
Try to use List(Of Integer) type instead of array. It seems it's untyped (unfortunately, I am not vb dev.)
Or set a ServiceKnownType attribute:
<ServiceContract>
Public Interface IMyService
<OperationContract>
<ServiceKnownType(GetType(Integer()))>
Function GetData() As Array
End Interface
By the way to simplify the process of investigating WCF issue it's useful to add error handling:
Error handling
For you case it's exception: Type 'System.Int32[]' with data contract name 'ArrayOfint:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

Sitecore 7 ContentSearch crawling failure: "Crawler : AddRecursive DoItemAdd failed"

When we try to rebuild our Lucene (ContentSearch) indexes, our CrawlingLog is filled up with these exceptions:
7052 15:08:21 WARN Crawler : AddRecursive DoItemAdd failed - {5A1E50E4-46B9-42D5-B743-1ED10D15D47E}
Exception: System.AggregateException
Message: One or more errors occurred.
Source: mscorlib
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body)
at Sitecore.ContentSearch.AbstractDocumentBuilder`1.AddItemFields()
at Sitecore.ContentSearch.LuceneProvider.CrawlerLuceneIndexOperations.GetIndexData(IIndexable indexable, IProviderUpdateContext context)
at Sitecore.ContentSearch.LuceneProvider.CrawlerLuceneIndexOperations.BuildDataToIndex(IProviderUpdateContext context, IIndexable version)
at Sitecore.ContentSearch.LuceneProvider.CrawlerLuceneIndexOperations.Add(IIndexable indexable, IProviderUpdateContext context, ProviderIndexConfiguration indexConfiguration)
at Sitecore.ContentSearch.SitecoreItemCrawler.DoAdd(IProviderUpdateContext context, SitecoreIndexableItem indexable)
at Sitecore.ContentSearch.HierarchicalDataCrawler`1.CrawlItem(Tuple`3 tuple)
Nested Exception
Exception: System.ArgumentOutOfRangeException
Message: Index and length must refer to a location within the string.
Parameter name: length
Source: mscorlib
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at Sitecore.Data.ShortID.Encode(String guid)
at Sitecore.ContentSearch.FieldReaders.MultiListFieldReader.GetFieldValue(IIndexableDataField indexableField)
at Sitecore.ContentSearch.FieldReaders.FieldReaderMap.GetFieldValue(IIndexableDataField field)
at Sitecore.ContentSearch.LuceneProvider.LuceneDocumentBuilder.AddField(IIndexableDataField field)
at System.Threading.Tasks.Parallel.<>c__DisplayClass32`2.<PartitionerForEachWorker>b__30()
at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
at System.Threading.Tasks.Task.<>c__DisplayClass11.<ExecuteSelfReplicating>b__10(Object param0)
This appears to be caused by the ShortID.Encode(string) method expecting the GUID in the string parameter to have brackets (" { " and " } ") around it. Some of our multilist field relationships were associated programmatically using Guid.ToString(), which does not include the brackets. Unfortunately, these values cause the ShortID.Encode() method to choke.
First things first: find all the places you call MultiListField.Add(string) and change Guid.ToString() to Guid.ToString("B"). This will resolve the issue for all new relationships.
Create a custom FieldReader class to replace the standard MultiListFieldReader (we called ours CustomMultiListFieldReader).
Set your custom class to inherit from Sitecore.ContentSearch.FieldReaders.FieldReader.
Decompile the Sitecore.ContentSearch.FieldReaders.MultiListFieldReader.GetFieldValue(IIndexableDataField) method into your custom class.
Before the if (ID.IsID(id)) line, add the following code:
if (!str.StartsWith("{") && !str.EndsWith("}"))
id = String.Format("{{{0}}}", str);
In your index configuration (we added ours to the default, Sitecore.ContentSearch.DefaultIndexConfiguration.config) change the fieldReaderType for the MultiList fields to your custom type. (This can be found in your config at sitecore/contentSearch/configuration/defaultIndexConfiguration/fieldReaders/mapFieldByTypeName/fieldReader.)
Full disclosure: I don't love this approach because if the default implementation of the MultiListFieldReader ever changed, we'd be without those changes. But this allows the items to be included in the index without reformatting all of the GUIDs in every multilist field.