Skip to content

Commit 050c7db

Browse files
fredrikhaglundBillWagner
authored andcommitted
Improve Getting Started Guide by removing inconsistencies in service names (dotnet#9659)
* Update how-to-host-and-run-a-basic-wcf-service.md - Fixed formatting of Important section. - Fixed inconsistency with different baseAddress in csharp and vb example (also aligned to what is used in other steps) - Updated instruction how to verify that your service is running. * Update how-to-host-and-run-a-basic-wcf-service.md - Incorporate instructions how to disable Start WCF Service Host when debugging to avoid conflicts.
1 parent be8c2db commit 050c7db

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

docs/framework/wcf/how-to-host-and-run-a-basic-wcf-service.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Module Service
9595
Class Program
9696
Shared Sub Main()
9797
' Step 1 Create a URI to serve as the base address
98-
Dim baseAddress As New Uri("http://localhost:8000/ServiceModelSamples/Service")
98+
Dim baseAddress As New Uri("http://localhost:8000/GettingStarted")
9999

100100
' Step 2 Create a ServiceHost instance
101101
Dim selfHost As New ServiceHost(GetType(CalculatorService), baseAddress)
@@ -138,26 +138,25 @@ End Module
138138

139139
**Step 3** – Creates a <xref:System.ServiceModel.Description.ServiceEndpoint> instance. A service endpoint is composed of an address, a binding, and a service contract. The <xref:System.ServiceModel.Description.ServiceEndpoint> constructor therefore takes the service contract interface type, a binding, and an address. The service contract is `ICalculator`, which you defined and implement in the service type. The binding used in this sample is <xref:System.ServiceModel.WSHttpBinding> which is a built-in binding that is used for connecting to endpoints that conform to the WS-* specifications. For more information about WCF bindings, see [WCF Bindings Overview](bindings-overview.md). The address is appended to the base address to identify the endpoint. The address specified in this code is "CalculatorService" so the fully qualified address for the endpoint is `"http://localhost:8000/GettingStarted/CalculatorService"`.
140140

141-
> [!IMPORTANT]
142-
> Adding a service endpoint is optional when using .NET Framework 4 or later. In these versions, if no endpoints are added in code or configuration, WCF adds one default endpoint for each combination of base address and contract implemented by the service. For more information about default endpoints see [Specifying an Endpoint Address](specifying-an-endpoint-address.md). For more information about default endpoints, bindings, and behaviors, see [Simplified Configuration](simplified-configuration.md) and [Simplified Configuration for WCF Services](./samples/simplified-configuration-for-wcf-services.md).
141+
> [!IMPORTANT]
142+
> Adding a service endpoint is optional when using .NET Framework 4 or later. In these versions, if no endpoints are added in code or configuration, WCF adds one default endpoint for each combination of base address and contract implemented by the service. For more information about default endpoints see [Specifying an Endpoint Address](specifying-an-endpoint-address.md). For more information about default endpoints, bindings, and behaviors, see [Simplified Configuration](simplified-configuration.md) and [Simplified Configuration for WCF Services](./samples/simplified-configuration-for-wcf-services.md).
143143
144144
**Step 4** – Enable metadata exchange. Clients will use metadata exchange to generate proxies that will be used to call the service operations. To enable metadata exchange create a <xref:System.ServiceModel.Description.ServiceMetadataBehavior> instance, set it’s <xref:System.ServiceModel.Description.ServiceMetadataBehavior.HttpGetEnabled%2A> property to `true`, and add the behavior to the <xref:System.ServiceModel.Description.ServiceDescription.Behaviors%2A> collection of the <xref:System.ServiceModel.ServiceHost> instance.
145145

146146
**Step 5** – Open the <xref:System.ServiceModel.ServiceHost> to listen for incoming messages. Notice the code waits for the user to hit enter. If you do not do this, the app will close immediately and the service will shut down.Also notice a try/catch block used. After the <xref:System.ServiceModel.ServiceHost> has been instantiated, all other code is placed in a try/catch block. For more information about safely catching exceptions thrown by <xref:System.ServiceModel.ServiceHost>, see [Use Close and Abort to release WCF client resources](samples/use-close-abort-release-wcf-client-resources.md)
147147

148148
> [!IMPORTANT]
149-
> Edit App.config in GettingStartedLib to reflect the changes made in code:
150-
> 1. Change line 14 to `<service name="GettingStartedLib.CalculatorService">`
151-
> 2. Change line 17 to `<add baseAddress = "http://localhost:8000/GettingStarted/CalculatorService" />`
152-
> 3. Change line 22 to `<endpoint address="" binding="wsHttpBinding" contract="GettingStartedLib.ICalculator">`
149+
> When you add a WCF Service Library, Visual Studio can host it for you when you debug by starting a service host. To avoid conflicts you can disable this.
150+
> 1. Open Project Properties for GettingStartedLib.
151+
> 2. Go to **WCF Options** and uncheck **Start WCF Service Host when debugging**.
153152
154153
## Verify the service is working
155154

156155
1. Run the GettingStartedHost console application from inside Visual Studio.
157156

158157
The service must be run with administrator privileges. Because Visual Studio was opened with administrator privileges, GettingStartedHost is also run with administrator privileges. You can also open a new command prompt using **Run as administrator** and run service.exe within it.
159158

160-
2. Open a web browser and browse to the service's debug page at `http://localhost:8000/GettingStarted/CalculatorService`.
159+
2. Open a web browser and browse to the service's debug page at `http://localhost:8000/GettingStarted/`. **Note! Ending slash is significant.**
161160

162161
## Example
163162

@@ -243,7 +242,7 @@ namespace GettingStartedHost
243242
static void Main(string[] args)
244243
{
245244
// Step 1 of the address configuration procedure: Create a URI to serve as the base address.
246-
Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/Service");
245+
Uri baseAddress = new Uri("http://localhost:8000/GettingStarted/");
247246

248247
// Step 2 of the hosting procedure: Create ServiceHost
249248
ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);
@@ -351,7 +350,7 @@ Module Service
351350
Class Program
352351
Shared Sub Main()
353352
' Step 1 of the address configuration procedure: Create a URI to serve as the base address.
354-
Dim baseAddress As New Uri("http://localhost:8000/ServiceModelSamples/Service")
353+
Dim baseAddress As New Uri("http://localhost:8000/GettingStarted/")
355354

356355
' Step 2 of the hosting procedure: Create ServiceHost
357356
Dim selfHost As New ServiceHost(GetType(CalculatorService), baseAddress)
@@ -404,4 +403,5 @@ For troubleshooting information, see [Troubleshooting the Getting Started Tutori
404403
## See also
405404

406405
- [Getting Started](samples/getting-started-sample.md)
407-
- [Self-Host](samples/self-host.md)
406+
- [Self-Host](samples/self-host.md)
407+
- [Hosting Services](hosting-services.md)

0 commit comments

Comments
 (0)