O'Reilly logo

Professional Visual Basic 2012 and .NET 4.5 Programming by Todd Herman, Gastón Hillar, David McCarter, Rob Windsor, Billy Hollis, Bill Sheldon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Namespaces

Note that the services built in the chapter have no defined namespaces. If you looked at the WSDL files that were produced, you would see that the namespace provided is http://tempuri.org. Obviously, you do not want to go live with this default namespace. Instead, you need to define your own namespace.

To accomplish this task, the interface's <ServiceContract()> attribute enables you to set the namespace:

<ServiceContract(Namespace:="http://www.Wrox.com/ns/")> _
Public Interface IHelloCustomer
    <OperationContract()> _
    Function HelloFirstName(ByVal cust As Customer) As String
    <OperationContract()> _
    Function HelloFullName(ByVal cust As Customer) As String
End Interface

Here, the <ServiceContract()> attribute uses the Namespace property to provide a namespace.

Building the Host

Next create a service host, using the same steps as before: Create a new Console Application project to act as the WCF service host. Name the new project ProVB_WCFWithDataContractHost and change the Module1.vb file so that it becomes the host of the WCF service you just built. Keep in mind that you'll need to add the appropriate project reference and System.ServiceModel references to the code. Once that is complete, the updated code will look similar to Listing 11.9:

Listing 11.9 : Service Host Implementation—ProVB_WCFWithDataContractHost\Module1.vb

Imports System.ServiceModel Imports System.ServiceModel.Description Module Module1 Sub Main() Using svcHost = New ServiceHost(GetType(ProVB_WCFWithDataContract.HelloCustomer)) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required