This sample demonstrates how to use the WebHttpRelayBinding binding to return binary data using the Web programming model.
Prerequisites
If you haven't already done so, please read the release notes document that explains how to sign up for a Windows Azure account and how to configure your environment.
Service
The service project defines a simple contract. The
OperationContractAttribute
and WebGetAttribute
attributes are applied
to the GetImage
method.
C# | |
---|---|
[ServiceContract(Name = "ImageContract", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")] public interface IImageContract { [OperationContract, WebGet] Stream GetImage(); } |
The ImageContract contract is implemented by the
ImageService
class. This class reads a bitmap from a file (included
in the solution). When GetImage
is called, the response returns a
message that contains the image. The configuration uses the
WebHttpRelayBinding
binding. Note that relayClientAuthenticationType
is set to None,
therefore the client credential is not required when sending an HTTP GET request.
Xml | |
---|---|
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings> <!-- Application Binding --> <webHttpRelayBinding> <binding name="default"> <security relayClientAuthenticationType="None" /> </binding> </webHttpRelayBinding> </bindings> <services> <!-- Application Service --> <service name="Microsoft.ServiceBus.Samples.ImageService" behaviorConfiguration="default"> <endpoint name="RelayEndpoint" contract="Microsoft.ServiceBus.Samples.IImageContract" binding="webHttpRelayBinding" bindingConfiguration="default" behaviorConfiguration="sharedSecretClientCredentials" address="" /> </service> </services> <behaviors> <endpointBehaviors> <behavior name="sharedSecretClientCredentials"> <transportClientEndpointBehavior credentialType="SharedSecret"> <clientCredentials> <sharedSecret issuerName="ISSUER_NAME" issuerSecret="ISSUER_SECRET"/> </clientCredentials> </transportClientEndpointBehavior> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="default"> <serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> |
Client
For this sample, the client can be any web browser. The browser can send an HTTP GET to the service, and the request is mapped to a GetImage operation.
Building and Running the Sample
Before building the solution, do the following to update the App.config file:
- Open the App.config file under the \Service project. Replace ISSUER_NAME with the actual issuer name and ISSUER_SECRET with the actual issuer secret.
After building the solution, perform the following steps to obtain the image:
- From a command prompt, run the service
(Service\bin\Debug\Service.exe).
- When prompted, enter the service namespace name.
- At this point, the service should indicate that it is listening at the
configured address.
- Navigate to the URL provided by the service using any Web browser, and view the
returned image.
Did you find this information useful? Please send your suggestions and comments about the documentation.