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

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...

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.

Consuming WCF return value of List(Of String) in WinForms

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.

ServiceRoute does not work when routePrefix is a path

When I try to access my WCF service at the following address it works fine:
http://localhost/webservices/main.svc
Great. But I want to be able to call this service in following way:
http://localhost/api/main
So I am attempting to put in the proper ServiceRoute within the RouteConfig definitions in my MVC. I am able to make the routing work when the routePrefix variable is singular. But I cannot get it to work when routePrefix it is a path such as, as in my case, I want to map a route to ~/api/main.
I've scoured around The Google and this particular question is not common. I am pretty much seeking to accomplish the similar to what is stated in the accepted answer of the following previously posted question on this topic:
Expose WCF services that belong to an Area in MVC app at a routed path
I also attempted to implement a route constraint as suggested here: http://geekswithblogs.net/michelotti/archive/2010/09/22/wcf-rest-services-inside-mvc-projects.aspx
But still get the following error:
No HTTP resource was found that matches the request URI 'http://localhost/api/main'.
No type was found that matches the controller named 'main'.
Here is what I've attempted so far:
Imports System.Web.Mvc
Imports System.Web.Routing
Imports System.ServiceModel.Activation
Imports MyServiceLibrary
Public Class RouteConfig
Public Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
[..other routing stuff...]
routes.Add(New ServiceRoute("api/main", New ServiceHostFactory(), _
GetType(MyServiceLibrary.main)))
routes.MapRoute("Default", "{controller}/{action}/{id}", New With { _
Key .controller = "Default1", _
Key .action = "Index", _
Key .id = UrlParameter.Optional}, _
New With {Key .controller = "^(?!main).*"})
[..other routing stuff...]
End Sub
End Class
Can't seem to figure out the fix on this.
EDIT 2:
When I first posted this question I had a problem with what turned out to be malformed VB syntax.
The original INCORRECT syntax:
routes.Add(new ServiceRoute("api/main", new ServiceHostFactory(), _
typeof(MyServiceLibrary.main)))
The CORRECT vb syntax should be:
routes.Add(New ServiceRoute("api/main", New ServiceHostFactory(), _
GetType(MyServiceLibrary.main)))
Notice that in VB you should use GetType instead of typeof. Fixing this was a good step forward, but did not solve the underlying problem.
EDIT 3:
Well, turns out if I modify the ServiceRoute as follows, then IT WORKS:
routes.Add(New ServiceRoute("main", New ServiceHostFactory(), _
GetType(MyServiceLibrary.main)))
So, the question is how to create the route i desire "api/main"...
EDIT 4:
I thought I might have found the solution here: Can a WCF ServiceRoute Route Prefix contain a path value?
The solution there notably implements WebServiceHostFactory instead of ServiceHostFactory. I tried it, but it didn't work for me.
You should pass in the wcf service type as Type. That is the service defined in your web.config file.
Take a look at this page:
http://blogs.msdn.com/b/endpoint/archive/2010/01/25/using-routes-to-compose-wcf-webhttp-services.aspx

Code Analysis Error: Declare types in namespaces

Is VS2010, I analyzed my code and got this error:
Warning 64 CA1050 : Microsoft.Design : 'ApplicationVariables' should be declared inside a namespace. C:\My\Code\BESI\BESI\App_Code\ApplicationVariables.vb 10 C:\...\BESI\
Here is some reference info on the error. Essentially, I tried to create a class to be used to access data in the Application object in a typed way.
The warning message said unless I put my (ApplicationVariables) class in a Namespace, that I wouldn't be able to use it. But I am using it, so what gives?
Also, here is a link to another StackOverflow article that talks about how to disable this warning in VS2008, but how would you disable it for 2010? There is no GlobalSuppressions.vb file for VS2010.
Here is the code it is complaining a bout:
Public Class ApplicationVariables
'Shared Sub New()
'End Sub 'New
Public Shared Property PaymentMethods() As PaymentMethods
Get
Return CType(HttpContext.Current.Application.Item("PaymentMethods"), PaymentMethods)
End Get
Set(ByVal value As PaymentMethods)
HttpContext.Current.Application.Item("PaymentMethods") = value
End Set
End Property
'Etc, Etc...
End Class
I suspect that the code you entered is in your App_Code fodler of your web app. This code is accessible from your web code as you have deomnstrated but is not accessible from any other assembly.
You can suppress the instance of the error by right mouse clicking on the particular error and selecting "Suppress Message In Source." That'll result in code being added to your source that says "the next time you check this error-fuggedabodit!"
When to Suppress Warnings
--------------------------------------------------------------------------------
While it is never necessary to suppress a warning from this rule, it is safe to do this when the assembly will never be used with other assemblies.
To suppress the error on all occurences, select "Suppress in Project Suppression File"