using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Microsoft.ServiceBus;
using System.ServiceModel.Description;
using Microsoft.ServiceBus.Description;
namespace Microsoft.ServiceBus.Samples
{
[ServiceContract(Name =
"IEchoContract", Namespace =
"http://samples.microsoft.com/ServiceModel/Relay/")]
public
interface IEchoContract
{
[OperationContract]
string Echo(string text);
}
public
interface IEchoChannel :
IEchoContract, IClientChannel { }
[ServiceBehavior(Name =
"EchoService", Namespace =
"http://samples.microsoft.com/ServiceModel/Relay/")]
class
EchoService : IEchoContract
{
public string Echo(string text)
{
Console.WriteLine("Echoing: {0}", text);
return text;
}
}
class
Program
{
static void Main(string[] args)
{
Console.Write("Your Service Namespace: ");
string serviceNamespace =
Console.ReadLine();
Console.Write("Your Issuer Name: ");
string issuerName =
Console.ReadLine();
Console.Write("Your Issuer Secret: ");
string issuerSecret =
Console.ReadLine();
TransportClientEndpointBehavior sharedSecretServiceBusCredential =
new TransportClientEndpointBehavior();
sharedSecretServiceBusCredential.CredentialType =
TransportClientCredentialType.SharedSecret;
sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerName = issuerName;
sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerSecret = issuerSecret;
Uri address =
ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace,
"EchoService");
ServiceBusEnvironment.SystemConnectivity.Mode =
ConnectivityMode.AutoDetect;
ServiceHost host =
new ServiceHost(typeof(EchoService), address);
IEndpointBehavior serviceRegistrySettings =
new ServiceRegistrySettings(DiscoveryType.Public);
foreach (ServiceEndpoint endpoint
in host.Description.Endpoints)
{
endpoint.Behaviors.Add(serviceRegistrySettings);
endpoint.Behaviors.Add(sharedSecretServiceBusCredential);
}
host.Open();
Console.WriteLine("Service address: " + address);
Console.WriteLine("Press [Enter] to exit");
Console.ReadLine();
host.Close();
}
}
}