Consume WCF service from Windows Service

Posted by Swat11 under WCF on 10/7/2010 | Points: 10 | Views : 9068 | Status : [Member] | Replies : 5
I need to call a WCF service hosted in IIS from Windows Service. Both the windows service and WCF service run under the sane local system.




Responses

Posted by: Peermohamedmydeen on: 10/7/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi,

In your windows forms application or windows service,

Project --> Add Service Reference --> Give the service URL (.svc) --> Give Name for the service.

Eg :

NameSpace == > Test
WCF Service ===> http://localhost/sOthers.svc


Let us assume we have given sMyService is our Service Name.

In your DAL or BAL or in you service layer, use the following

using  Test.sMyService;


IsOthersClient sServ = new IsOthersClient();

(or)

sMyService.IsOthersClient sServ = new sMyService.IsOthersClient();


Now sServ will have all webmethods from your service.











Swat11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Swat11 on: 10/7/2010 [Member] Starter | Points: 25

Up
0
Down
I am not getting the option IsOthersClient. I am using .net framework 3.5

Swat11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prasham on: 10/7/2010 [Member] Starter | Points: 25

Up
0
Down
Hello,

You need to add service reference by giving .svc file url.
This will create the proxy class for your WCF service.
Use the namespace of your proxy class in your code where you want to access the WCF method.
After including your proxy class namespace, you can use the <servicename>client class to create the client instance.
and with the help of this client instance you can call the operations of your service.

Hope this will help you. If still any confusion please revert back.

Thanks
Prasham


Thanks and Best Regards
Prasham

Swat11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Peermohamedmydeen on: 10/7/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi,

As Prasham said, you can create instance of the class "I<servicename>client" to access the methods.

check the option with your "ServiceName" .

Eg: http://localhost/sMyService.svc.

Then you can get the option, IsMyServiceClient class in the intellisense.






Swat11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 10/7/2010 [Member] Bronze | Points: 25

Up
0
Down
follow these steps for all the nodes on the client computer:

1. Click Start, click Run, type regedit, and then click OK.
2. Locate and then click the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
3. Right-click MSV1_0, point to New, and then click Multi-String Value.
4. In the Name column, type BackConnectionHostNames, and then press ENTER.
5. Right-click BackConnectionHostNames, and then click Modify.
6. In the Value data box, type the CNAME or the DNS alias, that is used for the local shares on the computer, and then click OK.

Note Type each host name on a separate line.

Note If the BackConnectionHostNames registry entry exists as a REG_DWORD type, you have to delete the BackConnectionHostNames registry entry.
7. Exit Registry Editor, and then restart the computer.
For another method you will get here
http://blogs.msdn.com/b/distributedservices/archive/2009/11/10/wcf-calling-wcf-service-hosted-in-iis-on-the-same-machine-as-client-throws-an-authentication-error.aspx

LP MER

Swat11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response