Private Async Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
Dim a As New DataService.DataClient
Dim q = Await a.GetCompaniesByUserAsync(My.User.Name)
GridControl1.DataSource = q
End Sub
Service code:
IData.vb
Imports System.ServiceModel
<ServiceContract>
Public Interface IData
<OperationContract>
Function DoWork() As String
<OperationContract>
Function GetCompaniesByUser(userName As String) As Company()
End Interface
Data.svc
Imports System.ComponentModel
Imports System.Data.Entity.DbExtensions
Public Class Data
Implements IData
Public Function DoWork() As String Implements IData.DoWork
Using db As New DataContext
Return db.Users.FirstOrDefault.Username
End Using
End Function
Public Function GetCompaniesByUser(userName As String) As Company() Implements IData.GetCompaniesByUser
Using db As New DataContext
'Dim user = db.Users.Where(Function(a) a.Username = userName).FirstOrDefault
'Dim q = db.Companies.Where(Function(u) u.Users.Contains(user))
'Return q
Return db.Companies.ToArray
End Using
End Function
End Class
Entity:
Company.vb
Public Class Company
Public Overridable Property CompanyId As Guid
Public Overridable Property Name As String
Public Overridable Property Description As String
Public Overridable Property Users As ICollection(Of User)
End Class
Error:
System.ServiceModel.CommunicationException was unhandled by user code
HResult=-2146233087
Message=An error occurred while receiving the HTTP response to http://localhost:50487/Service/Data.svc. 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.
Source=System.ServiceModel.Internals
StackTrace:
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass5`1.<CreateGenericTask>b__4(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Software.Main.VB$StateMachine_0_BarButtonItem1_ItemClick.MoveNext() in D:\Dev 2012\Sass\Software\Main.vb:line 18
InnerException: System.Net.WebException
HResult=-2146233079
Message=The underlying connection was closed: An unexpected error occurred on a receive.
Source=System
StackTrace:
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
InnerException: System.IO.IOException
HResult=-2146232800
Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Source=System
StackTrace:
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
at System.Net.PooledStream.EndRead(IAsyncResult asyncResult)
at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
InnerException: System.Net.Sockets.SocketException
HResult=-2147467259
Message=An existing connection was forcibly closed by the remote host
Source=System
ErrorCode=10054
NativeErrorCode=10054
StackTrace:
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
InnerException:
When i have my entity set-up like this it gives the error:
Public Class Company
Public Overridable Property CompanyId As Guid
Public Overridable Property Name As String
Public Overridable Property Description As String
Public Overridable Property Users As ICollection(Of User)
End Class
And when i have it like this (without Overridable/virtual) it works as expected, what the heck??
Public Class Company
Public Overridable Property CompanyId As Guid
Public Property Name As String
Public Overridable Property Description As String
Public Property Users As ICollection(Of User)
End Class
Whats even more wierd, what does it then work on Description which is same as Name????
Se3ker
Member
269 Points
118 Posts
Trying to use WCF services with .NET 4.5
Mar 19, 2012 02:12 PM|LINK
I am trying to use a WCF service this is my setup, code and error i get:
Target framework: .NET 4.5
Service host: MVC 4 application
Web.config:
<system.serviceModel> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.web.extensions> <scripting> <webServices> <authenticationService enabled="true" requireSSL = "false"/> <roleService enabled="true"/> </webServices> </scripting> </system.web.extensions>Client host: WinForms application
App.config:
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IData"> <security mode="None"> <transport clientCredentialType="None" /> <message clientCredentialType="UserName" /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost:50487/Service/Data.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IData" contract="DataService.IData" name="BasicHttpBinding_IData" /> </client> </system.serviceModel>Code that invokes service operation:
Private Async Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick Dim a As New DataService.DataClient Dim q = Await a.GetCompaniesByUserAsync(My.User.Name) GridControl1.DataSource = q End SubService code:
IData.vb
Imports System.ServiceModel <ServiceContract> Public Interface IData <OperationContract> Function DoWork() As String <OperationContract> Function GetCompaniesByUser(userName As String) As Company() End InterfaceData.svc
Imports System.ComponentModel Imports System.Data.Entity.DbExtensions Public Class Data Implements IData Public Function DoWork() As String Implements IData.DoWork Using db As New DataContext Return db.Users.FirstOrDefault.Username End Using End Function Public Function GetCompaniesByUser(userName As String) As Company() Implements IData.GetCompaniesByUser Using db As New DataContext 'Dim user = db.Users.Where(Function(a) a.Username = userName).FirstOrDefault 'Dim q = db.Companies.Where(Function(u) u.Users.Contains(user)) 'Return q Return db.Companies.ToArray End Using End Function End ClassEntity:
Company.vb
Public Class Company Public Overridable Property CompanyId As Guid Public Overridable Property Name As String Public Overridable Property Description As String Public Overridable Property Users As ICollection(Of User) End ClassError:
System.ServiceModel.CommunicationException was unhandled by user code HResult=-2146233087 Message=An error occurred while receiving the HTTP response to http://localhost:50487/Service/Data.svc. 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. Source=System.ServiceModel.Internals StackTrace: at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result) at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass5`1.<CreateGenericTask>b__4(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Software.Main.VB$StateMachine_0_BarButtonItem1_ItemClick.MoveNext() in D:\Dev 2012\Sass\Software\Main.vb:line 18 InnerException: System.Net.WebException HResult=-2146233079 Message=The underlying connection was closed: An unexpected error occurred on a receive. Source=System StackTrace: at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) InnerException: System.IO.IOException HResult=-2146232800 Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. Source=System StackTrace: at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) at System.Net.PooledStream.EndRead(IAsyncResult asyncResult) at System.Net.Connection.ReadCallback(IAsyncResult asyncResult) InnerException: System.Net.Sockets.SocketException HResult=-2147467259 Message=An existing connection was forcibly closed by the remote host Source=System ErrorCode=10054 NativeErrorCode=10054 StackTrace: at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) InnerException:necro_mancer
Star
8089 Points
1590 Posts
Re: Trying to use WCF services with .NET 4.5
Mar 20, 2012 02:37 AM|LINK
hi there,
would you please check the server log and paste the actual error message here? Thanks
Professional SQL 2008 R2 Service
Se3ker
Member
269 Points
118 Posts
Re: Trying to use WCF services with .NET 4.5
Mar 20, 2012 07:35 AM|LINK
OK, so ive edited my web.config to add the diagnostics
</configuration> ..... <system.serviceModel> <diagnostics> <messageLogging logEntireMessage="true" logMalformedMessages="false" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="false" maxMessagesToLog="3000" maxSizeOfMessageToLog="2000"/> </diagnostics> </system.serviceModel> ...... <system.diagnostics> <sources> <source name="System.ServiceModel.MessageLogging"> <listeners> <add name="messages" type="System.Diagnostics.XmlWriterTraceListener" initializeData="D:\LogFiles\messages.svclog" /> </listeners> </source> </sources> </system.diagnostics> ...... </configuration>And the messages.svclog did get created but its empty when viewed with SvcTraceViewer
Se3ker
Member
269 Points
118 Posts
Re: Trying to use WCF services with .NET 4.5
Mar 20, 2012 08:06 AM|LINK
When enabling all logging i get this:
https://skydrive.live.com/redir.aspx?cid=fd6f686e8d62ac75&resid=FD6F686E8D62AC75!924&parid=FD6F686E8D62AC75!107&authkey=!AJIPPEz77fTGZJc
Se3ker
Member
269 Points
118 Posts
Re: Trying to use WCF services with .NET 4.5
Mar 20, 2012 10:27 AM|LINK
Hmm, something very wierd is going on.
When i have my entity set-up like this it gives the error:
Public Class Company Public Overridable Property CompanyId As Guid Public Overridable Property Name As String Public Overridable Property Description As String Public Overridable Property Users As ICollection(Of User) End ClassAnd when i have it like this (without Overridable/virtual) it works as expected, what the heck??
Public Class Company Public Overridable Property CompanyId As Guid Public Property Name As String Public Overridable Property Description As String Public Property Users As ICollection(Of User) End ClassWhats even more wierd, what does it then work on Description which is same as Name????