Anda di halaman 1dari 3

Simple example:


Step1 file -> new -> web site-> wcf service-> location http-> Step2: define service contract and operation contract in interface eg imyservice And write function in class myservice Step3: add system.servicemodel reference Step4: make sure in iis manager, password is controlled by iis checkbox is unchecked Step5: Change binding from wsHTTPBinding to basicHttpBinding in web.config file.. Run the service RUN SVCUTIL IN VISUAL STUDIO COMMAND PROMPT

Svcutil.exe /language:vb /out:generatedProxy.vb /config:app.config /ct:System.Collections.Generic.List`1


add /ct:System.Collections.Generic.List`1 in above command if service returns collections datatype like arrylist, list(of string) , etc.,

SHD GET TWO OUTPUT FILES-> ONE CODE FILE AND APP.CONFIG CLIENT CODE file contains class it is MyServiceClient use this class name in client app Create client app in any language, copy above generated 2 files and add it to client app.. Eg client app : Dim ep As New EndpointAddress("http://localhost/IISHostedService/MyService.svc") Dim client As MyServiceClient client = New MyServiceClient(New WSHttpBinding(), ep) MsgBox(client.HelloWorld("Ramasdas"))

DONE --------------------------------------------------------------------

2nd method

WCF Service tutorial:

Create a vb project Change the default Service namespace to Microsoft.ServiceModel.Samples. To do this, rightclick the project in the Solution Explorer and select Properties. Make sure that the Application tab on the left side of the Properties dialog is selected. For a C# project, type Microsoft.ServiceModel.Samples in the edit box labeled Default Namespace. For a VB project, type Microsoft.ServiceModel.Samples in the edit box labeled Root namespace. Click the File menu and select Save All to save your changes. Add a namespace stmnt Namespace Microsoft.ServiceModel.Samples Module Module1 Sub Main() End Sub End Module End Namespace

Add reference to System.ServiceModel Define a new interface called ICalculator and apply the ServiceContractAttribute attribute to the interface with a Namespace Define operation contract for each of the method you want to expose

Create a new class called CalculatorService Implement each method defined in the ICalculator interface within the CalculatorService class.

Create a base address for the service. Create a service host for the service. Enable metadata exchange. Open the service host. Close the service host

Add a new project to existing project called client Add referenfce System.ServiceModel.dll go to visual studio tool_> command prompt-> svcutil.exe /language:vb /out:generatedProxy.vb /config:app.config http://localhost:8888/ServiceModelSamples/service

can c two output files app.config and generatedproxy.vb in below path -> C:\Program Files\Microsoft Visual Studio 9.0\VC

Add both files generated in above step to Client project

Dim epAddress As New EndpointAddress("http://localhost:8000/ServiceModelSamples/Service/CalculatorService") Dim Client As New CalculatorClient(New WSHttpBinding(), epAddress) Code to input values Client.close

Run service project and then run client project