Last post May 03, 2015 09:22 AM by mgebhard
May 02, 2015 04:26 AM|TwoSeven|LINK
I have a solution that contains a console application and a service project. When I include the service project in the console application by using 'Add Service Reference', the code that is generated contains incorrect namespaces where the namespace of
the console application is prepended to the namespace of the service entered in the 'Add Service Reference' dialog. This means that the application will not compile giving a missing assembly error.
I am using VS2013.4 C# and .Net 4.5
In the solution I have added a basic hello world service with a contract IHelloWorld and Implementation file HelloWorldImpl. There is a single method returning a data class Int32 GetWorldId( MyWorld ). MyWorld is defined as a DataContract with DataMember
methods Id and Name.
On the service contract and data contracts I have set a namespace
When I generate the service reference in the console application, I use 'Discover' change the name of servicereference1 to HelloWorld.Service, then click advanced and uncheck 'reuse types in referenced assemblies'.
The namespace of the console application is HelloWorld.Console
The code that gets generated in references.cs under the service reference contains incorrect CLR namespace references. All of the CLR namespaces generated are set to HelloWorld.Console.HelloWorld.Service none of them are accessible and I get a compile
error. If I remove the 'HellowWorld.Console' part manually the code compiles cleanly, but I still cannot access the service class or methods.
I have added a NameSpaceMapping to the Reference.svcmap file, however, the end result is that it does not appear to link in the references.cs file that is generated (I cannot access any data members).
Does anyone have an idea on how to get this working?
Note: If I press F5 and run the WCF service to get the WCF Service Host console, I can manually use svcutil with the /namespace:*,HelloWorld.Service parameter to get the code generated. However, I need to be able to automate this as part of the build process
(hence add service reference).
May 02, 2015 08:43 AM|mgebhard|LINK
Why are you using HelloWorld.Console as the namespace of a Console project? That creates a mess and defeats the purpose of using a namespace in the first place. Don't ya have to have to fully qualify every single Console.WriteLine() to System.Console.Writeline()
and every method call to HelloWorld.Console.MyMethod?
Select different namesspaces!
May 02, 2015 04:20 PM|TwoSeven|LINK
May 03, 2015 08:38 AM|mgebhard|LINK
What is the error? Post your source code.
May 03, 2015 09:22 AM|mgebhard|LINK
I created a test case and receive an error.
Error 1 The type or namespace name 'Console' does not exist in the namespace 'HelloWorld.Console.HelloWorld' (are you missing an assembly reference?)
I fixed the error by renaming the namespaces. I changed HelloWorld.Console to HelloWorld.ClientConsole. I did this so I don't have to fully qualify System.Console.WriteLine() every time I write to the output stream.
I gave the service a namespace of WcfProxy in the "Add Service Reference". The namespace becomes HelloWorld.ClientConsole.WcfProxy . If you want a specific namespace other than HelloWorld.ClientConsole then use the service utility.
There is no reason to rerun the the service utility during deployment. Only the URL properties needs updating.