Skip to content

Commit cce10ad

Browse files
Incorprate peer review input.
1 parent 8478211 commit cce10ad

File tree

5 files changed

+27
-20
lines changed

5 files changed

+27
-20
lines changed
-509 Bytes
Loading
-397 Bytes
Loading
Loading

articles/service-bus-relay/service-bus-relay-rest-tutorial.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ To begin using the relay features in Azure, you must first create a service name
4848

4949
## Define a REST-based WCF service contract to use with Azure Relay
5050

51-
When you create a WCF REST-style service, you must define the contract. The contract specifies what operations the host supports. A service operation can be thought of as a web service method. Define a contract with a C++, C#, or Visual Basic interface. Each method in the interface corresponds to a specific service operation. Apply the [ServiceContractAttribute](/dotnet/api/system.servicemodel.servicecontractattribute) attribute to each interface, and apply the [OperationContractAttribute](/dotnet/api/system.servicemodel.operationcontractattribute) attribute to each operation. If a method in an interface that has the [ServiceContractAttribute](/dotnet/api/system.servicemodel.servicecontractattribute) doesn't have the [OperationContractAttribute](/dotnet/api/system.servicemodel.operationcontractattribute), that method isn't exposed. The code used for these tasks appears in the example following the procedure.
51+
When you create a WCF REST-style service, you must define the contract. The contract specifies what operations the host supports. A service operation resembles a web service method. Define a contract with a C++, C#, or Visual Basic interface. Each method in the interface corresponds to a specific service operation. Apply the [ServiceContractAttribute](/dotnet/api/system.servicemodel.servicecontractattribute) attribute to each interface, and apply the [OperationContractAttribute](/dotnet/api/system.servicemodel.operationcontractattribute) attribute to each operation.
52+
53+
> [!TIP]
54+
> If a method in an interface that has the [ServiceContractAttribute](/dotnet/api/system.servicemodel.servicecontractattribute) doesn't have the [OperationContractAttribute](/dotnet/api/system.servicemodel.operationcontractattribute), that method isn't exposed. The code used for these tasks appears in the example following the procedure.
5255
5356
The primary difference between a WCF contract and a REST-style contract is the addition of a property to the [OperationContractAttribute](/dotnet/api/system.servicemodel.operationcontractattribute): [WebGetAttribute](/dotnet/api/system.servicemodel.web.webgetattribute). This property enables you to map a method in your interface to a method on the other side of the interface. This example uses the [WebGetAttribute](/dotnet/api/system.servicemodel.web.webgetattribute) attribute to link a method to `HTTP GET`. This approach enables Service Bus to accurately retrieve and interpret commands sent to the interface.
5457

@@ -92,7 +95,7 @@ Next, make the following code changes to the project:
9295
...
9396
```
9497

95-
1. Directly after the opening curly brace of the namespace declaration, define a new interface named `IImageContract` and apply the `ServiceContractAttribute` attribute to the interface with a value of `https://samples.microsoft.com/ServiceModel/Relay/RESTTutorial1`. The namespace value differs from the namespace that you use throughout the scope of your code. The namespace value is a unique identifier for this contract, and should have version information. For more information, see [Service Versioning](/dotnet/framework/wcf/service-versioning). Specifying the namespace explicitly prevents the default namespace value from being added to the contract name.
98+
1. Directly after the opening curly brace of the namespace declaration, define a new interface named `IImageContract` and apply the `ServiceContractAttribute` attribute to the interface with a value of `https://samples.microsoft.com/ServiceModel/Relay/RESTTutorial1`.
9699
97100
```csharp
98101
[ServiceContract(Name = "ImageContract", Namespace = "https://samples.microsoft.com/ServiceModel/Relay/RESTTutorial1")]
@@ -101,6 +104,8 @@ Next, make the following code changes to the project:
101104
}
102105
```
103106

107+
The namespace value differs from the namespace that you use throughout the scope of your code. The namespace value is a unique identifier for this contract, and should have version information. For more information, see [Service Versioning](/dotnet/framework/wcf/service-versioning). Specifying the namespace explicitly prevents the default namespace value from being added to the contract name.
108+
104109
1. Within the `IImageContract` interface, declare a method for the single operation that the `IImageContract` contract exposes in the interface and apply the `OperationContract` attribute to the method that you want to expose as part of the public Service Bus contract.
105110

106111
```csharp
@@ -170,7 +175,7 @@ namespace Microsoft.ServiceBus.Samples
170175

171176
## Implement the REST-based WCF service contract
172177

173-
To create a REST-style WCF Relay service, first create the contract by using an interface. The next step is to implement the interface. This procedure involves creating a class named `ImageService` that implements the user-defined `IImageContract` interface. After you implement the contract, you then configure the interface by using an *App.config* file. The configuration file contains necessary information for the application. This information includes the name of the service, the name of the contract, and the type of protocol that is used to communicate with the relay service. The code used for these tasks is provided in the example following the procedure.
178+
To create a REST-style WCF Relay service, first create the contract by using an interface. The next step is to implement the interface. This procedure involves creating a class named `ImageService` that implements the user-defined `IImageContract` interface. After you implement the contract, you then configure the interface by using an *App.config* file. The configuration file contains necessary information for the application. This information includes the name of the service, the name of the contract, and the type of protocol that is used to communicate with the relay service. The code used for these tasks appears in the example following the procedure.
174179

175180
As with the previous steps, there's little difference between implementing a REST-style contract and a WCF Relay contract.
176181

@@ -197,15 +202,17 @@ As with the previous steps, there's little difference between implementing a RES
197202

198203
As mentioned previously, this namespace isn't a traditional namespace. It's part of the WCF architecture that identifies the contract. For more information, see the [Data Contract Names](/dotnet/framework/wcf/feature-details/data-contract-names/).
199204

200-
1. Add a .jpg image to your project.
205+
1. Add a *.jpg* image to your project. This file is a picture that the service displays in the receiving browser.
201206

202-
This file is a picture that the service displays in the receiving browser. Right-click your project and select **Add**. Then select **Existing Item**. Use **Add Existing Item** to browse to an appropriate .jpg, and then select **Add**. When adding the file, make sure that **All Files** is selected in the drop-down list next to **File name**.
207+
1. Right-click your project and select **Add**.
208+
1. Then select **Existing Item**.
209+
1. Use **Add Existing Item** to browse to an appropriate .jpg, and then select **Add**. When adding the file, select **All Files** from the drop-down list next to **File name**.
203210

204-
The rest of this tutorial assumes that the name of the image is *image.jpg*. If you have a different file, you must rename the image, or change your code to compensate.
211+
The rest of this tutorial assumes that the name of the image is *image.jpg*. If you have a different file, you must rename the image, or change your code to compensate.
205212

206213
1. To make sure that the running service can find the image file, in **Solution Explorer** right-click the image file, then choose **Properties**. In **Properties**, set **Copy to Output Directory** to **Copy if newer**.
207214

208-
1. Use the procedure in [#to-create-a-contract-with-an-interface](#to-create-a-contract-with-an-interface) to add a reference to the *System.Drawing.dll* assembly to the project.
215+
1. Use the procedure in [To create a contract with an interface](#to-create-a-contract-with-an-interface) to add a reference to the *System.Drawing.dll* assembly to the project.
209216

210217
1. Add the following associated `using` statements:
211218

@@ -247,7 +254,7 @@ As with the previous steps, there's little difference between implementing a RES
247254
}
248255
```
249256

250-
This implementation uses `MemoryStream` to retrieve the image and prepare it for streaming to the browser. It starts the stream position at zero, declares the stream content as a jpeg, and streams the information.
257+
This implementation uses `MemoryStream` to retrieve the image and prepare it for streaming to the browser. It starts the stream position at zero, declares the stream content as a *.jpg*, and streams the information.
251258

252259
1. Select **Build** > **Build Solution**.
253260

@@ -293,7 +300,7 @@ As with the previous steps, there's little difference between implementing a RES
293300

294301
This content configures a service that uses the previously defined default `webHttpRelayBinding`. It also uses the default `sbTokenProvider`, which is defined in the next step.
295302

296-
1. After the `<services>` element, create a `<behaviors>` element with the following content, replacing `SAS_KEY` with the Shared Access Signature (SAS) key you previously obtained from the [Azure portal][Azure portal].
303+
1. After the `<services>` element, create a `<behaviors>` element with the following content, replacing `SAS_KEY` with the Shared Access Signature (SAS) key. To obtain an SAS key from the [Azure portal][Azure portal], see [Get management credentials](service-bus-relay-tutorial.md#get-management-credentials).
297304

298305
```xml
299306
<behaviors>
@@ -485,7 +492,7 @@ The following example shows the *App.config* file associated with the service.
485492

486493
## Host the REST-based WCF service to use Azure Relay
487494

488-
This section describes how to run a web service using a console application with WCF Relay. A complete listing of the code written in this section is provided in the example following the procedure.
495+
This section describes how to run a web service using a console application with WCF Relay. A complete listing of the code written in this section appears in the example following the procedure.
489496

490497
### To create a base address for the service
491498

@@ -627,7 +634,7 @@ After building the solution, do the following to run the application:
627634

628635
Now that you've built an application that uses the Azure Relay service, see the following articles to learn more:
629636

630-
* [Azure Relay overview](relay-what-is-it.md)
631-
* [How to use the WCF relay service with .NET](service-bus-relay-tutorial.md)
637+
* [What is Azure Relay?](relay-what-is-it.md)
638+
* [Expose an on-premises WCF REST service to external client by using Azure WCF Relay](service-bus-relay-tutorial.md)
632639

633640
[Azure portal]: https://portal.azure.com

articles/service-bus-relay/service-bus-relay-tutorial.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ This tutorial describes how to build a WCF Relay client application and service
2323

2424
Working through this tutorial gives you an understanding of the steps to create a WCF Relay client and service application. Like their original WCF counterparts, a service is a construct that exposes one or more endpoints. Each endpoint exposes one or more service operations. The endpoint of a service specifies an address where the service can be found, a binding that contains the information that a client must communicate with the service, and a contract that defines the functionality provided by the service to its clients. The main difference between WCF and WCF Relay is that the endpoint is exposed in the cloud instead of locally on your computer.
2525

26-
After you work through the sequence of sections in this tutorial, you'll have a running service. You'll also have a client that can invoke the operations of the service. The first section describes how to set up an account. The next sections describe how to define a service that uses a contract, how to implement the service, and how to configure the service in code. They also describe how to host and run the service. The service is self-hosted and the client and service run on the same computer. You can configure the service by using either code or a configuration file.
27-
28-
The final three sections describe how to create a client application, configure the client application, and create and use a client that can access the functionality of the host.
26+
After you work through the sequence of sections in this tutorial, you'll have a running service. You'll also have a client that can invoke the operations of the service.
2927

3028
You do the following tasks in this tutorial:
3129

@@ -51,7 +49,7 @@ To complete this tutorial, you need the following prerequisites:
5149

5250
## Create a Relay namespace
5351

54-
The first step is to create a namespace, and to obtain a [Shared Access Signature (SAS)](../service-bus-messaging/service-bus-sas.md) key. A namespace provides an application boundary for each application exposed through the relay service. A SAS key is automatically generated by the system when a service namespace is created. The combination of service namespace and SAS key provides the credentials for Azure to authenticate access to an application.
52+
The first step is to create a namespace, and to obtain a [Shared Access Signature (SAS)](../service-bus-messaging/service-bus-sas.md) key. A namespace provides an application boundary for each application exposed through the relay service. An SAS key is automatically generated by the system when a service namespace is created. The combination of service namespace and SAS key provides the credentials for Azure to authenticate access to an application.
5553

5654
[!INCLUDE [relay-create-namespace-portal](../../includes/relay-create-namespace-portal.md)]
5755

@@ -87,7 +85,7 @@ The service contract specifies what operations the service supports. Operations
8785
> This tutorial uses the C# namespace `Microsoft.ServiceBus.Samples` which is the namespace of the contract-based managed type that is used in the configuration file in the [Configure the WCF client](#configure-the-wcf-client) section. You can specify any namespace you want when you build this sample. However, the tutorial will not work unless you then modify the namespaces of the contract and service accordingly, in the application configuration file. The namespace specified in the *App.config* file must be the same as the namespace specified in your C# files.
8886
>
8987

90-
1. Directly after the `Microsoft.ServiceBus.Samples` namespace declaration, but within the namespace, define a new interface named `IEchoContract` and apply the `ServiceContractAttribute` attribute to the interface with a namespace value of `https://samples.microsoft.com/ServiceModel/Relay/`. The namespace value differs from the namespace that you use throughout the scope of your code. Instead, the namespace value is used as a unique identifier for this contract. Specifying the namespace explicitly prevents the default namespace value from being added to the contract name. Paste the following code after the namespace declaration:
88+
1. Directly after the `Microsoft.ServiceBus.Samples` namespace declaration, but within the namespace, define a new interface named `IEchoContract` and apply the `ServiceContractAttribute` attribute to the interface with a namespace value of `https://samples.microsoft.com/ServiceModel/Relay/`. Paste the following code after the namespace declaration:
9189
9290
```csharp
9391
[ServiceContract(Name = "IEchoContract", Namespace = "https://samples.microsoft.com/ServiceModel/Relay/")]
@@ -96,6 +94,8 @@ The service contract specifies what operations the service supports. Operations
9694
}
9795
```
9896

97+
The namespace value differs from the namespace that you use throughout the scope of your code. Instead, the namespace value is used as a unique identifier for this contract. Specifying the namespace explicitly prevents the default namespace value from being added to the contract name.
98+
9999
> [!NOTE]
100100
> Typically, the service contract namespace contains a naming scheme that includes version information. Including version information in the service contract namespace enables services to isolate major changes by defining a new service contract with a new namespace and exposing it on a new endpoint. In this manner, clients can continue to use the old service contract without having to be updated. Version information can consist of a date or a build number. For more information, see [Service Versioning](/dotnet/framework/wcf/service-versioning). For this tutorial, the naming scheme of the service contract namespace does not contain version information.
101101
>
@@ -273,7 +273,7 @@ This step describes how to run an Azure Relay service.
273273

274274
The SAS key will be used later to access your project. The namespace is passed as a parameter to `CreateServiceUri` to create a service URI.
275275

276-
1. Using a [TransportClientEndpointBehavior](/dotnet/api/microsoft.servicebus.transportclientendpointbehavior) object, declare that you'll be using a SAS key as the credential type. Add the following code directly after the code added in the last step.
276+
1. Using a [TransportClientEndpointBehavior](/dotnet/api/microsoft.servicebus.transportclientendpointbehavior) object, declare that you'll be using an SAS key as the credential type. Add the following code directly after the code added in the last step.
277277

278278
```csharp
279279
TransportClientEndpointBehavior sasCredential = new TransportClientEndpointBehavior();
@@ -762,15 +762,15 @@ namespace Microsoft.ServiceBus.Samples
762762

763763
`Enter text to echo (or [Enter] to exit):`
764764

765-
Enter some text to send to the service application and press Enter. This text is sent to the service through the Echo service operation and appears in the service console window as in the following example output.
765+
Enter some text to send to the service application and select Enter. This text is sent to the service through the Echo service operation and appears in the service console window as in the following example output.
766766

767767
`Echoing: My sample text`
768768

769769
The client application receives the return value of the `Echo` operation, which is the original text, and prints it to its console window. The following text is example output from the client console window.
770770

771771
`Server echoed: My sample text`
772772

773-
1. You can continue sending text messages from the client to the service in this manner. When you're finished, press Enter in the client and service console windows to end both applications.
773+
1. You can continue sending text messages from the client to the service in this manner. When you're finished, select Enter in the client and service console windows to end both applications.
774774

775775
## Next steps
776776

0 commit comments

Comments
 (0)