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

Get Professional Visual Basic 2012 and .NET 4.5 Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.