Consuming WCF return value of List(Of String) in WinForms - vb.net

I've just started to get rid of Web Services and implement WCF instead. But once I tried to add the following method with a List(Of String) return value, my WCF ServiceReference - which was added successfully - had became unreadable in my WinForms client application code. i.e. It was not defined.
The scenario is pretty simple:
I am creating an OperationContract named ServerMessages with a list of string return value.
This is the interface:
<ServiceContract()>
Public Interface ICommunicationHandler
<OperationContract()>
Function ServerMessages() As List(Of String)
End Interface
And there is the implementation class:
Public Class CommunicationHandler
Implements ICommunicationHandler
Public Function ServerMessages() As List(Of String) _
Implements ICommunicationHandler.ServerMessages
Dim messages As New List(Of String)
messages.Add("First Message")
messages.Add("Second Message")
Return messages
End Function
End Class
There is my client application code:
Dim locServ As New LocalReference.CommunicationHandlerClient
TextBox1.Text += "First Server Messages:" & vbLf & locaServ.ServerMessages(0)
I've tried removing the service reference from the project and re-adding it, but this doesn't solved the problem. On the other hand, removing that specific method ServerMessages() makes the ServiceReference available again in my code. I've even tried to define the type List(Of String) in the Service Interface by adding this attribute:
<ServiceKnownType(GetType(List(Of String)), ServiceContract()>
but nothing had changed.
EDIT
I've noticed this warning in the client application Error window:
Warning 2 Custom tool warning: Cannot import wsdl:port Detail: There
was an error importing a wsdl:binding that the wsdl:port is dependent
on. XPath to wsdl:binding:
//wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:binding[#name='BasicHttpBinding_ICommunicationHandler']
XPath to Error Source:
//wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:service[#name='CommunicationHandler']/wsdl:port[#name='BasicHttpBinding_ICommunicationHandler'] D:\WCTApp\Service
References\LocalReference\Reference.svcmap
Thanks in advance.

My problem was solved by unchecking the [Reuse types in referenced assemblies] in the WCF ServiceReference configuration of my client application. Thanks Steve for letting me having another check on it.
The problem - in this case - was that I've added some references in the service (Google Drive references) which was not defined in my application and therefore causing the ServiceReference not to read the service appropriately. Since I decided not to use these references, I should had eliminated them both from my client application as well as the WCF Service. Now that I stopped using these references in my client application, everything worked as it is supposed to be.
This was my mistake but maybe someone else will fall into the exact same issue and find this situation helpful.

Related

VB.NET Connected SAP WSDL Preventing Solution from building

I'm trying to build a .NET Class Library that utilises a SAP generated WSDL.
In the reference.vb file that one of the WSDLs generates, I'm getting the following error in this line:
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified, Order:=0)> _
With the error being BC30369 Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. on System.
This only occurs within one of the generated Partial Public Classes that it generates, and not the rest.
After removing System it works:
'''
<System.Xml.Serialization.XmlElementAttribute(Form:=Xml.Schema.XmlSchemaForm.Unqualified)>
Public Property MESSAGE_V4() As String
Get
Return Me.mESSAGE_V4Field
End Get
Set
Me.mESSAGE_V4Field = Value
End Set
End Property

Broken Reference.vb generated after update to VS2012

In my WCF service I have the following OperationContract:
<OperationContract()>
Function getResults(ByVal Settings As Dictionary(Of String, String)) As IO.Stream
...and MessageContract:
<MessageContract()>
Public Class FI
Implements IDisposable
<MessageHeader(MustUnderstand:=True)_
Public id as Integer
<MessageHeader(MustUnderstand:=True)_
Public token as String
<MessageHeader(MustUnderstand:=True)_
Public length as Long
<MessageHeader(MustUnderstand:=True)_
Public del as Char
<MessageHeader(Order:=1)_
Public stream as System.IO.Stream`
Public Sub Dispose() Implements IDisposable.Dispose
FI.Close()
FI=Nothing
End Sub
End Class
On the client side after configuring the service in VS and updating I get multiple errors:
1) For getResults: Instead of the Dictionary an ArrayOfKeyValueOfstringstringKeyValueOfstringstring is expected. I already declared the operation contract as <OperationContract(), ServiceKnownType(GetType(Dictionary(Of String, String)))> without success. My client settings are CollectionType = Generic.List and DictionaryCollectionType = Generic.Dictionary. I also tried deleting and adding the service again.
2) For FI: The method signature that uses the MessageContract FI expects the parameter del to be of type Integer. Here I have no idea what to do.
I have to add, that everything was working fine until recently, the only change I can remember is updating Visual Studio from 2010 to 2012.
I just found out that the underlying problem was an update to .NET 4.5. That's what I did on the machine running VS2010 where the generation used to work. Downgrading to .NET 4.0 did the trick. The generation from within VS is working again.
In conclusion: not a problem of the VS version but of the .NET version of the machine where VS is executed. I guess that the svcutil (or whatever resource the "Update Service Reference" function in VS uses) contained in .NET 4.5 is responsible for the bug.

VS: Update Service Reference creates requirement for "Global" prefixes in Reference.vb

VB 2012
WCF & EF 6.1*
I have a client and a web service. When I recompile/change the WS, I go back to my client, and 'Update Service Reference'. Works like a charm-except, the resulting Reference.vb in the client complains that any classes that were defined from the server have a Global. prefix; To be precise, the error description is:
Error 9 Type 'serverNamespace.CountryName' is not defined.
C:\...\UpdateServiceReference\Reference.vb
...where UpdateServiceReference is the client side proxy.
Public Interface IUpdateService
[...]
<System.ServiceModel.OperationContractAttribute(Action:="http://...", ReplyAction:="http://.../IUpdateService/GetClientCountriesResponse")> _
Function GetClientCountries(ByVal placeHolder As Boolean) As serverNamespace.CountryName()
[...]
End Interface
This service reference/proxy on the client only imports from system stuff and the server's namespace's entities. My only settings/imports at the top of the compiler-created Reference.vb are:
Option Strict On
Option Explicit On
Imports System
Imports System.Runtime.Serialization
But here is the really strange (well, confusing) part. In order to clear out the generated errors in the Error List:
Type 'serverNamespace.CountryName' is not defined. Change 'serverNamespace.CountryName' to
'Global.serverNamespace.CountryName'.
I need to do as the compiler suggests above, and change (in Reference.vb) any line with something like this:
Function GetClientCountries(ByVal placeHolder As Boolean) As serverNamespace.CountryName()
...to...
Function GetClientCountries(ByVal placeHolder As Boolean) As Global.serverNamespace.CountryName()
---at EVERY place in both class body & interface... And everything works!
How can I decorate my Web Service to just make it work?
I've already tried using all kinds of "Imports" in the WS code, but nothing has any effect... And just stupidly adding a Global prefix to the existing WS code won't compile...

QBFC WCF Service Error

I have a new blank Wcf Service in vs.net 2013 express. I have added the reference to the qbfc12.dll and did the import Imports QBFC12Lib. I run the blank wcf service and it works fine. I then add one line of code and it breaks and gives me a error.
Function that works fine:
Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData
Return String.Format("You entered: {0}", value)
End Function
Function that gives exception(One line of code added only):
Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData
Dim SessionManager As New QBSessionManager
Return String.Format("You entered: {0}", value)
End Function
I get the following exception on that line:
An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll but was not handled in user code
Additional information: Retrieving the COM class factory for component with CLSID {C693D8F1-180B-4F82-B735-8F511B566718} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
Can anyone please help me? I have a wcf server written on my laptop, that runs perfect. I am only trying to move it to my production server, but does not work. So removed all the code down to this one line of code that is giving the issue, but it all worked fine on my laptop.
The QBFC12 installer needs to be run on the machine your application is executing from. It is available for download in the link below. You have to sign up to download the installer, but there's no cost and you don't even have to verify your email.
Page with all installers:
https://developer.intuit.com/docs/0200_quickbooks_desktop/0400_tools/quickbooks_desktop/download_the_sdk
Installer in question:
QBFC12_Installer (Version 12.0.0.29)
https://developer.intuit.com/Downloads/Restricted?filename=qbfc12_0installer.exe

Unity Container Type Registration Quirk

I'm trying to automatically register all reports in a unity container.
All reports implement IReport and also have a Report() attribute which defines the title, description and unique key (so I can read these without instantiating a concrete class).
So...
I get the report types like this
Public Shared Function GetClassesWhichimplementInterface(Of T)() As IEnumerable(Of Type)
Dim InterfaceType = GetType(T)
Dim Types As IEnumerable(Of Type)
Types = Reflection.Assembly.GetCallingAssembly.GetTypes()
Return Types.Where(Function(x) InterfaceType.IsAssignableFrom(x))
End Function
And register them like this:
Public Sub RegisterReports()
Dim ReportTypes = ReflectionHelper.GetClassesWhichimplementInterface(Of IReport)()
For Each ReportType In ReportTypes
''Previously I was reading the report attribute here and using the defined unique key. I've stopped using this code to remove possible problems while debugging.
Container.RegisterType(GetType(IReport), ReportType, ReportType.Name)
Next
End Sub
There are types being returned by the call to GetClassesWhichimplementInterface() and the Container.RegisterType() call is made without errors. If I call Container.Resolve(of Interfaces.IReport) immediately after the register call, I get the following exception:
Resolution of the dependency failed, type = "MyProject.Interfaces.IReport", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The current type, MyProject.Interfaces.IReport, is an interface and cannot be constructed. Are you missing a type mapping?
-----------------------------------------------
At the time of the exception, the container was:
Resolving MyProject.Interfaces.IReport,(none)
Can anyone tell me why the container isn't preserving the registration?
The registration is in the container. The thing is that you are calling resolve without passing a named registration as a parameter.
As all your registrations were performed using the following code:
Container.RegisterType(GetType(IReport), ReportType, ReportType.Name)
Then all of them have a name. You must provide the name along with the type to be able to resolve the dependency from the container.
The error you are getting is because there is no type mapping registered without a name.