Sunday, January 6, 2013

Create And test WCF Service

1>Create a simple WCF service

 
2>Now Change the service name to the desired service name[Find and replace old service Name with new one]

3>Add the Endpoint of REST & SOAP like following

4>Add the host address.
Host address should be=> http://Domain Name/Service Virtual Directory\n EX:http://localhost/MyService

5>Now addd the EndPoint behaviors for webHttp

6>Now add a Service Method in the interface
Note:Add the "System.ServiceModel.Web" As reference

7>Inherit the service method and defined it in the following way


8>Create a virtual directory say "MyService" and specify the virtual directory path to the WCF Service path

9>Right Click on the WCF Service and Click on Properties. Here Start URL Should be :
http://domain name/Service Virtual Directory/SVC file name/EndPoint Name/URITemplate Name
EX:http://localhost/MyService/MyService.svc/REST/MyAction

9>Specify IIS Home directory path to the WCF Service path

10>So WCF service is now hosted in IIS


11>Now to test the service we need to create a console application
We can call the service asynchronously as well as synchronously
To call the service Synchronously we need to do the following things

To Call the service Asynchronously we need to do the following things

How to Host A WCF Service in IIS server
1>Create A WCF service and set the IIS home directory as the service path

2>Specify the start up url in the IIS location as
http://domain name/Service Virtual Directory/SVC file name/EndPoint Name/URITemplate Name
EX:http://localhost/MyService/MyService.svc/REST/MyAction

3>Create virtual directory and specify the service path as it's path

4>Add the host location in the config file
Note:Here MyService is the created service virtual directory

Service Tag Under <system.serviceModel>

Behavior Tag Under <system.serviceModel>

REST SERVICE ERROR
1>The remote server return an error method not allowed
Sol:This error is generated because of wrong way of method request.Suppose WCF service accept POST request but client request the service method with GET
2>The remote server returned an error: (400) Bad Request
Sol:This error is generated because of wrong type/parameter request.Also if from service end if any error occur then also we get this type of error

How to debugg WCF Service
i)TO debug the WCF service first, we need to host it in IIS
ii)Run the application from where WCF service is consumed.
iii)From Editor navigate to Debugg=>Attach The Process=>Attach the WCF service Process or attach the aspnet_wp.exe
iv)Keep the break point in appropriate position and to go throught the break point press F5

No comments: