rdlecler
04-09-2009, 01:31 PM
I've had trouble figuring out WCF services and even more trouble getting this hosted on DASP. I really feel that DASP should have taken the initiative and put such tutorials up themselves, but in the absence I have prepared one which shows how to build a bare bones WCF and then I sow you exactly how to publish it to your site hosted on discountasp.net. I also attached the the code. You will need to configure web.config to set the address of your website.
Most of the this I got service I got from these 4 (amazing) PluralSight video-casts:
Creating WCF Service (Part 1) (http://channel9.msdn.com/posts/cliff.simpkins/Endpoint-Screencasts-Creating-Your-First-WCF-Service/)
Creating WCF Client (Part 2) (http://channel9.msdn.com/shows/Endpoint/Endpoint-Screencasts-Creating-Your-First-WCF-Client/)
Configuring Services with EndPoints (Part 3) (http://channel9.msdn.com/posts/cliff.simpkins/Endpoint-Screencasts-Configuring-Services-with-Endpoints/)
Hosting WCF Services in IIS (Part 4) (http://channel9.msdn.com/posts/cliff.simpkins/Endpoint-Screencasts-Hosting-WCF-Services-in-IIS/)
If you follow those then the only changes you need to make at the end are to the web.config file. I'll post mine below although I use slightly different names to better help me distinguish between which class is which.
==========================
Contents:
==========================
Section 1: Over view of steps
Section 2: My Configuration and assumptions
Section 3: Detailed step-by-step process
Section 4: The set of code snippets you should have
Section 5: My Web.config
==========================
Section 1: Over view of steps
==========================
////Part I (Setting Up the service in VS2008)
1-2: Create the service Library Project
3-4: Create the Data object which will be passed through your WCF service
5: Create a service CONTRACT used by the client to INTERFACE with the service implementation
7-8: Implement the methods specified in the service CONTRACT
9: Set up the serviceModel for the service
10: Specify what protocol will be used to interact with the service (ie: basicHttpBinding, wsHttpBinding...)
11: Specify the endpoint address for the service discovery (mexHttpBinding)
12-13: Test local access to the service using Visual Studio's "WcfTestClient.exe" util.
/////Part II (Setting Up the service to be hosted on DASP)
14: Create a WCFService Website that will be published on discountasp.net
15: Set up your .svc service that you can point to in your browser. (**Don't forget to remove the "code behind" in the .svc**)
16: Copy the files created in your Servicelibrary to the WebSiteService project
17: Remove everything from web.config that is not needed to run our service. (**Dont forget to add in the base address to your dasp website**)
18: Set the binding to basicHttpBinding (Not sure if wsHttpBinding also works)
19: Copy the website folder and all of its contents to your discoutasp.net root directory
20: Make your application service directory an application in DASP the host panel.
21: Disable basic authentication using the IIS7.0 application tool (**I don't know if you can do it without IIS7??**)
22: Test remote access to the service using Visual Studio's "WcfTestClient.exe" util.
==================================
Section 2: My Configuration and assumptions
==================================
1) VisualStudio=2008(SP1)
-VSRoot="C:\Program Files\Microsoft Visual Studio 9.0"
2) .NET=3.5(SP1)
3) discountasp.net's Web server=IIS7.0
4) OS=WindowsXP
5) Project Root: C:\
6) Project Name: EvalServiceLibrary
7) Using IIS7.0 Manager
===============================
Section 3: Detailed step-by-step process
===============================
1) Open V2008. Select: File->New->Project
-Select: Project types="Visual C#"->"WCF"
-Select: Templates="WCF ServiceLibrary"
-Set: Name="EvalServiceLibrary"
-Set: Location="C:\"
-CheckBox: Create directory for solution=true
-Set: Solution Name="EvalServiceLibrary"
-Select: "Okay"
2) In "SolutionExplorer": Delete files {IService1.cs, Service1.cs}
//We will create our own
3) In "Solution Explorer" RightClick on Solution "EvalService Library"
-Select: "Add New Item"
-Select: Categories="Visual C# Items"
-Select: Templated="Class"
-Set: Name="EvalDataObject.cs"
-Select: "Okay"
4) In "EvalDataObject.cs" code window delete all, replace with the following
-Copy and Paste Code Section: EvalDataObject.cs (See Code below)
5) In "Solution Explorer" RightClick on Solution "EvalServiceLibrary"
-Select: "Add New Item"
-Select: Categories="Visual C# Items"
-Select: Templated="Interface"
-Set: Name="IEvalServiceInterfaceContract.cs"
-Select: "Okay"
6) In "IEvalServiceInterfaceContract.cs" code window:
-Delete all code.
-Copy and Paste Code Section: IEvalServiceInterfaceContract.cs (See Code below)
7) In "Solution Explorer" RightClick on Solution "EvalService Library"
-Select: "Add New Item"
-Select: Categories="Visual C# Items"
-Select: Templated="Class"
-Set: Name="EvalServiceImplementationOfContract.cs"
-Select: "Okay"
8) In "EvalServiceImplementationOfContract.cs" code window:
-Delete all code.
-Copy and Paste Code Section: "EvalServiceImplementationOfContract.cs" (See Code below)
9) In "Solution Explorer" under "EvalService Library"
-RightClick on: App.config
-Select: "Edit WCF Configuration"
-In "Configuration Tree"
-Select: "Services"->"EvalServiceLibrary.Service1"
-In "Service: EvalServiceLibrary.Service1" "Tree
-Click on "General"->"Name" field
-Open Dialog Box in "Name" Field
-Navigate to: bin\Debug
-DoubleClickOn: EvalServiceLibrary.dll
-Select: EvalServiceLibrary.EvalServiceImplementationOfCont ract
-Select: "OK"
10) Still in the in the "WCF Cofiguration" Dialoge:
-Select: "EvalServiceLibrary.EvalServiceImplementationOfCont ract"->"EndPoints"
-Select first "(Empty Name)" in tree menu
-In "Service Endpoint" menu:
-Select: Endpoint Properties
-Click on address text field
-Set Address="ws"
-Double Click on "Contract" Field
-Navigate to: bin\Debug
-DoubleClickOn: EvalServiceLibrary.dll
-Select: EvalServiceLibrary.EvalServiceImplementationOfCont ract
11) Still in the in the "WCF Cofiguration"
-Select the second "(Empty Name)" in tree menu
-In the "Service Endpoint" menu:
-Select: Endpoint Properties
-Click on address text field
-Set Address="mex"
12) Close "WCF Configuration" and accept save changes
-Rebuild
-Select "F5" to run the "WCF Test Client"
13) When "WCF Test Client" Dialogue pops up
-DoubleClick->"SubmitEval()" in Tee menue
-Set: Comments="My Comments"
-Set: Submitted="Me"
-Click: "Invoke" Button.
-Select: "GetEvals()"
-Click: "Invoke" Button.
-Observe the data you submitted and retrieved from your service.
-Stop running (Debig->
14) In main workbench select "File"->"Add New Web Site"
-Select Template="WCF Service"
-Set Filename="C:\EvalServiceWebSite"
-Set Language="Visual C#"
-Click "Okay"
15) Go to "Solution Explorer" under "C:\EvalServiceWebSite"->App_Code
-Delete {IService.cs, Service.cs}
-Select: Service.svc
-Rename: Service.svc -> EvalNetService
-RightClick on "EvalNetService.svc"->"View In Markup"
-Delete all code.
-Copy and Paste Code Section: EvalService.svc (See Code below)
-Rebuild
16) Go to "Solution Explorer" under
-RightClick on "C:\EvalServiceWebSite"
-Select: "Add Reference"->(Tab)"Projects"->"EvalServiceLibrary"
//This copies the .dll and EvalServiceLibrary.pbd to your website
16) In "Solution Explorer" under "EvalServiceLibrary"->"C:\EvalServiceWebSite"
-RightClick on: Web.onfig
-Select: "Edit WCF Configuration"
-In "Configuration Tree"
-Select: "Services"->"Service"
-In "Service: EvalServiceLibrary.Service1" "Tree
-Click on "General"->"Name" field
-Open Dialog Box in "Name" Field
-Navigate to: "C:\EvalServiceLibrary\bin\Debug" in Library Directory
-DoubleClickOn: EvalServiceLibrary.dll
-Select: EvalServiceLibrary.EvalServiceImplementationOfCont ract
-Select: "OK"
17) Go to the web.config text editor.
-Delete everything not within the <configuration><system.ServiceModel> tags
-Delete the "<host>" tags and their contents (If there is one)
-Delete the "<identity><dns value="localhost"/></identity>
-Within the <configuration><system.ServiceModel>
-Copy and Paste Code Section: "serviceHostingEnvironment" (See Code below)
18) Go back to web.config "WCF Configuration" editor
-Select: Services->EvalServiceLibrary.EvalServiceImplementationOFCont ract->Endpoints
-For wsHttpBinding
-Set: Address="basic"
-Set: binding="basicHttpBinding"
-Click on "Name" field & Open Dialog Box
-Navigate to: "c:\evalservicewebsite\Bin" in website service Directory
-DoubleClickOn: EvalServiceLibrary.dll
-Select: "EvalServiceLibrary.IEvalServiceInterfaceContract"
-Select: "OK"
19) Open up FTP and login to your discount.asp site
-Drag and drop "c:\EvalServiceWebSite" to your base FTP directory.
20) Login to discount.asp.net's "Hosting Control Panel"
-Select: Tools&Utilities->Web Application Tool
-In tree menue select: "EvalServiceWebSite"
-Click the Add Application button.
-Go to Tools&Utilities->IIS Tools
-Restart WebServer.
21) Start the IIS 7.0 Manager on your computer
-Connect to your webserver
-Click on your root directory
-Select "Authentication"
-RightRightClick on "Basic" and "disable" authentication
22) Point browser to: "http://yourdomainname.com/EvalServiceWebSite/EvalService.svc"
-Ensure you have a page which asks you to create a client with svcutil.exe
-Go to you Visual Studio's instalation directoy
-Search for "WcfTestClient.exe"
-Open command line and run "wcfTestClient.exe http://yourdomain.com/EvalServiceWebSite/EvalService.svc"
Most of the this I got service I got from these 4 (amazing) PluralSight video-casts:
Creating WCF Service (Part 1) (http://channel9.msdn.com/posts/cliff.simpkins/Endpoint-Screencasts-Creating-Your-First-WCF-Service/)
Creating WCF Client (Part 2) (http://channel9.msdn.com/shows/Endpoint/Endpoint-Screencasts-Creating-Your-First-WCF-Client/)
Configuring Services with EndPoints (Part 3) (http://channel9.msdn.com/posts/cliff.simpkins/Endpoint-Screencasts-Configuring-Services-with-Endpoints/)
Hosting WCF Services in IIS (Part 4) (http://channel9.msdn.com/posts/cliff.simpkins/Endpoint-Screencasts-Hosting-WCF-Services-in-IIS/)
If you follow those then the only changes you need to make at the end are to the web.config file. I'll post mine below although I use slightly different names to better help me distinguish between which class is which.
==========================
Contents:
==========================
Section 1: Over view of steps
Section 2: My Configuration and assumptions
Section 3: Detailed step-by-step process
Section 4: The set of code snippets you should have
Section 5: My Web.config
==========================
Section 1: Over view of steps
==========================
////Part I (Setting Up the service in VS2008)
1-2: Create the service Library Project
3-4: Create the Data object which will be passed through your WCF service
5: Create a service CONTRACT used by the client to INTERFACE with the service implementation
7-8: Implement the methods specified in the service CONTRACT
9: Set up the serviceModel for the service
10: Specify what protocol will be used to interact with the service (ie: basicHttpBinding, wsHttpBinding...)
11: Specify the endpoint address for the service discovery (mexHttpBinding)
12-13: Test local access to the service using Visual Studio's "WcfTestClient.exe" util.
/////Part II (Setting Up the service to be hosted on DASP)
14: Create a WCFService Website that will be published on discountasp.net
15: Set up your .svc service that you can point to in your browser. (**Don't forget to remove the "code behind" in the .svc**)
16: Copy the files created in your Servicelibrary to the WebSiteService project
17: Remove everything from web.config that is not needed to run our service. (**Dont forget to add in the base address to your dasp website**)
18: Set the binding to basicHttpBinding (Not sure if wsHttpBinding also works)
19: Copy the website folder and all of its contents to your discoutasp.net root directory
20: Make your application service directory an application in DASP the host panel.
21: Disable basic authentication using the IIS7.0 application tool (**I don't know if you can do it without IIS7??**)
22: Test remote access to the service using Visual Studio's "WcfTestClient.exe" util.
==================================
Section 2: My Configuration and assumptions
==================================
1) VisualStudio=2008(SP1)
-VSRoot="C:\Program Files\Microsoft Visual Studio 9.0"
2) .NET=3.5(SP1)
3) discountasp.net's Web server=IIS7.0
4) OS=WindowsXP
5) Project Root: C:\
6) Project Name: EvalServiceLibrary
7) Using IIS7.0 Manager
===============================
Section 3: Detailed step-by-step process
===============================
1) Open V2008. Select: File->New->Project
-Select: Project types="Visual C#"->"WCF"
-Select: Templates="WCF ServiceLibrary"
-Set: Name="EvalServiceLibrary"
-Set: Location="C:\"
-CheckBox: Create directory for solution=true
-Set: Solution Name="EvalServiceLibrary"
-Select: "Okay"
2) In "SolutionExplorer": Delete files {IService1.cs, Service1.cs}
//We will create our own
3) In "Solution Explorer" RightClick on Solution "EvalService Library"
-Select: "Add New Item"
-Select: Categories="Visual C# Items"
-Select: Templated="Class"
-Set: Name="EvalDataObject.cs"
-Select: "Okay"
4) In "EvalDataObject.cs" code window delete all, replace with the following
-Copy and Paste Code Section: EvalDataObject.cs (See Code below)
5) In "Solution Explorer" RightClick on Solution "EvalServiceLibrary"
-Select: "Add New Item"
-Select: Categories="Visual C# Items"
-Select: Templated="Interface"
-Set: Name="IEvalServiceInterfaceContract.cs"
-Select: "Okay"
6) In "IEvalServiceInterfaceContract.cs" code window:
-Delete all code.
-Copy and Paste Code Section: IEvalServiceInterfaceContract.cs (See Code below)
7) In "Solution Explorer" RightClick on Solution "EvalService Library"
-Select: "Add New Item"
-Select: Categories="Visual C# Items"
-Select: Templated="Class"
-Set: Name="EvalServiceImplementationOfContract.cs"
-Select: "Okay"
8) In "EvalServiceImplementationOfContract.cs" code window:
-Delete all code.
-Copy and Paste Code Section: "EvalServiceImplementationOfContract.cs" (See Code below)
9) In "Solution Explorer" under "EvalService Library"
-RightClick on: App.config
-Select: "Edit WCF Configuration"
-In "Configuration Tree"
-Select: "Services"->"EvalServiceLibrary.Service1"
-In "Service: EvalServiceLibrary.Service1" "Tree
-Click on "General"->"Name" field
-Open Dialog Box in "Name" Field
-Navigate to: bin\Debug
-DoubleClickOn: EvalServiceLibrary.dll
-Select: EvalServiceLibrary.EvalServiceImplementationOfCont ract
-Select: "OK"
10) Still in the in the "WCF Cofiguration" Dialoge:
-Select: "EvalServiceLibrary.EvalServiceImplementationOfCont ract"->"EndPoints"
-Select first "(Empty Name)" in tree menu
-In "Service Endpoint" menu:
-Select: Endpoint Properties
-Click on address text field
-Set Address="ws"
-Double Click on "Contract" Field
-Navigate to: bin\Debug
-DoubleClickOn: EvalServiceLibrary.dll
-Select: EvalServiceLibrary.EvalServiceImplementationOfCont ract
11) Still in the in the "WCF Cofiguration"
-Select the second "(Empty Name)" in tree menu
-In the "Service Endpoint" menu:
-Select: Endpoint Properties
-Click on address text field
-Set Address="mex"
12) Close "WCF Configuration" and accept save changes
-Rebuild
-Select "F5" to run the "WCF Test Client"
13) When "WCF Test Client" Dialogue pops up
-DoubleClick->"SubmitEval()" in Tee menue
-Set: Comments="My Comments"
-Set: Submitted="Me"
-Click: "Invoke" Button.
-Select: "GetEvals()"
-Click: "Invoke" Button.
-Observe the data you submitted and retrieved from your service.
-Stop running (Debig->
14) In main workbench select "File"->"Add New Web Site"
-Select Template="WCF Service"
-Set Filename="C:\EvalServiceWebSite"
-Set Language="Visual C#"
-Click "Okay"
15) Go to "Solution Explorer" under "C:\EvalServiceWebSite"->App_Code
-Delete {IService.cs, Service.cs}
-Select: Service.svc
-Rename: Service.svc -> EvalNetService
-RightClick on "EvalNetService.svc"->"View In Markup"
-Delete all code.
-Copy and Paste Code Section: EvalService.svc (See Code below)
-Rebuild
16) Go to "Solution Explorer" under
-RightClick on "C:\EvalServiceWebSite"
-Select: "Add Reference"->(Tab)"Projects"->"EvalServiceLibrary"
//This copies the .dll and EvalServiceLibrary.pbd to your website
16) In "Solution Explorer" under "EvalServiceLibrary"->"C:\EvalServiceWebSite"
-RightClick on: Web.onfig
-Select: "Edit WCF Configuration"
-In "Configuration Tree"
-Select: "Services"->"Service"
-In "Service: EvalServiceLibrary.Service1" "Tree
-Click on "General"->"Name" field
-Open Dialog Box in "Name" Field
-Navigate to: "C:\EvalServiceLibrary\bin\Debug" in Library Directory
-DoubleClickOn: EvalServiceLibrary.dll
-Select: EvalServiceLibrary.EvalServiceImplementationOfCont ract
-Select: "OK"
17) Go to the web.config text editor.
-Delete everything not within the <configuration><system.ServiceModel> tags
-Delete the "<host>" tags and their contents (If there is one)
-Delete the "<identity><dns value="localhost"/></identity>
-Within the <configuration><system.ServiceModel>
-Copy and Paste Code Section: "serviceHostingEnvironment" (See Code below)
18) Go back to web.config "WCF Configuration" editor
-Select: Services->EvalServiceLibrary.EvalServiceImplementationOFCont ract->Endpoints
-For wsHttpBinding
-Set: Address="basic"
-Set: binding="basicHttpBinding"
-Click on "Name" field & Open Dialog Box
-Navigate to: "c:\evalservicewebsite\Bin" in website service Directory
-DoubleClickOn: EvalServiceLibrary.dll
-Select: "EvalServiceLibrary.IEvalServiceInterfaceContract"
-Select: "OK"
19) Open up FTP and login to your discount.asp site
-Drag and drop "c:\EvalServiceWebSite" to your base FTP directory.
20) Login to discount.asp.net's "Hosting Control Panel"
-Select: Tools&Utilities->Web Application Tool
-In tree menue select: "EvalServiceWebSite"
-Click the Add Application button.
-Go to Tools&Utilities->IIS Tools
-Restart WebServer.
21) Start the IIS 7.0 Manager on your computer
-Connect to your webserver
-Click on your root directory
-Select "Authentication"
-RightRightClick on "Basic" and "disable" authentication
22) Point browser to: "http://yourdomainname.com/EvalServiceWebSite/EvalService.svc"
-Ensure you have a page which asks you to create a client with svcutil.exe
-Go to you Visual Studio's instalation directoy
-Search for "WcfTestClient.exe"
-Open command line and run "wcfTestClient.exe http://yourdomain.com/EvalServiceWebSite/EvalService.svc"