using System; using Microsoft.Web.Services2; using Microsoft.Web.Services2.Addressing; using Microsoft.Web.Services2.Configuration; using Microsoft.Web.Services2.Messaging; using Microsoft.Web.Services2.Messaging.Configuration; using Microsoft.Web.Services2.Referral; namespace Router { public class AnyRouter:SoapReceiver { public AnyRouter() { Pipeline.IsIntermediary = true; } protected override void Receive(SoapEnvelope envelope) { Uri newAddress = ReferralCache.ResolvePath(envelope.Context.Addressing.To.Value); if( newAddress == null ) { throw new AddressingFault( AddressingFault.EndpointUnavailableMessage, AddressingFault.EndpointUnavailableCode ); } ISoapTransport transport = WebServicesConfiguration.MessagingConfiguration.GetTransport(newAddress.Scheme); if(transport == null) { throw new AddressingFault("Unsupported Transport", AddressingFault.ServerFaultCode); } envelope.Context.Addressing.Via = newAddress; ISoapOutputChannel channel = SoapTransport.StaticGetOutputChannel(envelope.Context.Addressing.Destination); try { channel.Send(envelope); } finally { channel.Close(); } } } }