BizTalk Integration with Windows Azure AppFabric Service Bus : Publishing Service Bus messages to BizTalk Server (part 7) - Reconfiguring a BizTalk solution to use Service Bus binding
8. Reconfiguring a BizTalk solution to use Service Bus binding
If you wanted BizTalk Server to listen to the cloud prior to the release of BizTalk Server 2010 AppFabric Connect for Services, you had to manually configure a WCF-CustomIsolated endpoint that used a Service Bus binding. This wasn't a particularly challenging thing to do; however, there was a problem in getting metadata easily shared since the Service Bus bindings don't fully respect the serviceMetadata WCF behavior that is often used to share a WSDL for a service. The updated service-generation wizard for BizTalk Server 2010 takes care of this problem by producing cloud-visible MEX endpoints.
What we can do is rebuild our previously-built, BizTalk-generated services, but this time, choose the option to extend our endpoints to the cloud. Note that for the purpose of future-cloud-enablement, we previously created two distinct services earlier rather than one service with two endpoints. The new wizard doesn't support that concept of two service endpoints in the same solution, so we needed two distinct service projects. For this example, we will only rebuild (and cloud enable) the RequestAccessService.
From within Visual Studio 2010, start the BizTalk WCF Service Publishing Wizard and choose the WCF-CustomIsolated adapter. Also choose to have a metadata endpoint and a receive location in the Chapter 6 application.
On the next wizard page, choose the option to Add a Service Bus endpoint. If you do not see this option, verify that you have indeed installed the BizTalk Server 2010 Feature Pack.
Choose the option to build a web service from schemas.
Rebuild the service to look the same as our initial RequestAccessService did.&;
Set the target namespace of the service to http://Chapter6/BuildingAccessManagement
Set the deployment location to http://localhost/RequestAccessService and make sure to select the option to overwrite the existing service.
The subsequent wizard page shows up because we earlier chose the option to build a Service Bus endpoint.
Choose the BasicHttpRelayBinding and enter your personal Service Bus namespace value in the Service Namespace field. Also, choose the option to Enable metadata exchange on cloud. This means that we have a distinct cloud endpoint in our service that exposes the metadata description. You can also choose to make this service discoverable in your Service Bus namespace's ATOM feed if you so choose.&;
After defining our Service Bus endpoints, we choose the service authentication parameters. In our case, we use the WatsonBSafe issuer and associated issuer key. The configuration below shows that pulling the service metadata does not require client authentication, but actually invoking the service requires the caller to authenticate with the Service Bus.
Complete the wizard which overwrites our existing web service and receive location. Go into the BizTalk Administration console, find the generated receive location and reset the binding to BasicHttpBinding (NOT the cloud relay binding) and re-add our custom claim authorization behavior using the previously outlined values.
Find the wizard-generated web service and investigate the web.config file. Notice that we now have three total endpoints: one for the on-premises metadata exchange, one for the cloud metadata exchange, and one for the cloud relay. Instead of leveraging the receive location configuration to define the service endpoint, the wizard added the cloud-required settings to the Azure AppFabric web service endpoint. However, this means that our custom authorization behavior will NOT get automatically applied to our cloud relay endpoint. The behavior must be manually added to the AppFabric endpoint as it will not be pulled from the receive location's configuration.
Find the endpoint behavior named sharedSecretClientCredentials and add a configuration block for our custom behavior using identical values as our receive location behavior.
<ClaimVerificationBehavior
serviceNamespace="<your namespace>"
trustedTokenPolicyKey= <your key here> acsHostName="accesscontrol.windows.net" trustedAudience="http://localhost/BuildingAccessManagementService" claimType="ActivityPermission"
claimValue="Create" />Save the web.config file and browse the service endpoint in the browser and confirm that our endpoint is configured correctly.
9. Reconfiguring the Service Consumer to use Service Bus Binding
All that's left to do now is call our service through the cloud relay. The steps below outline the changes to the client code to make this happen.
To call our new cloud endpoint in the Chapter6.ServiceConsumer.WinUI Windows Forms project, we have a few changes to make to the existing code. First, add a reference to the System.ServiceBus.dll and a "using" statement in the form's code. Then, in the form's button click event, redefine the binding variable using a BasicHttpRelayBinding type.
BasicHttpRelayBinding binding = new BasicHttpRelayBinding(EndToEndBasicHttpSecurityMode.Transport, RelayClientAuthenticationType.RelayAccessToken);
Next, change the endpoint address to now point to the cloud-hosted endpoint.
EndpointAddress address = new EndpointAddress("https://richardseroter.servicebus.windows.net/RequestAccessService/RequestAccessService.svc");In order to pass in our Service Bus authentication token that gives us the claims necessary to invoke the service, we need to define a TransportClientEndpointBehavior. We are using the SharedSecret credential type and passing in our vendor credentials for the Service Bus.
TransportClientEndpointBehavior sbBehavior = new TransportClientEndpointBehavior();
sbBehavior.CredentialType =
TransportClientCredentialType.SharedSecret; sbBehavior.Credentials.SharedSecret.IssuerName =
"Riley Semiconductor"; sbBehavior.Credentials.SharedSecret.IssuerSecret =
"HwWbATe00bCpxszylPdJoVns+FNfJCdgK2lUErcWJAE=";Finally, after our channel factory definition, we add our endpoint behavior.
factory.Endpoint.Behaviors.Add(sbBehavior);
Save and compile the client application.
If we use the correct sender ("Employee") when submitting a message to the cloud endpoint, then we see the message travel through BizTalk Server and come to rest on the file system. If we try and call the service with an invalid sender type ("Site Manager"), then we receive the HTTP 401 error.
In this demonstration, we saw how to build a custom authorization manager and apply it to an on-premises BizTalk-generated web service. It was then fairly easy to come along later and extend that on-premises service with cloud endpoints. This is a powerful scenario for extended existing, internal endpoints through the cloud to a select group of external users.