Вы можете создать свой собственный сервис маршрутизации.Создайте интерфейс для службы маршрутизации с контрактом all ("*")
[ServiceContract]
public interface IRoutingService
{
[WebInvoke(UriTemplate = "")]
[OperationContract(AsyncPattern = true, Action = "*", ReplyAction = "*")]
IAsyncResult BeginProcessRequest(Message requestMessage, AsyncCallback asyncCallback, object asyncState);
Message EndProcessRequest(IAsyncResult asyncResult);
}
Затем внедрите это в службу
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,
AddressFilterMode = AddressFilterMode.Any, ValidateMustUnderstand = false)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class RoutingService : IRoutingService, IDisposable
{
private IRoutingService _client;
public IAsyncResult BeginProcessRequest(Message requestMessage, AsyncCallback asyncCallback, object asyncState)
{
ClientSection clientSection = (ClientSection)ConfigurationManager.GetSection("system.serviceModel/client");
string clientEndPoint = clientSection.Endpoints[0].Address.AbsoluteUri;
string methodCall = requestMessage.Headers.To.AbsolutePath.Substring(requestMessage.Headers.To.AbsolutePath.IndexOf(".svc") + 4);
Uri uri = new Uri(clientEndPoint + "/" + methodCall);
EndpointAddress endpointAddress = new EndpointAddress(uri);
WebHttpBinding binding = new WebHttpBinding("JsonBinding");
var factory = new ChannelFactory<IRoutingService>(binding, endpointAddress);
// Set message address
requestMessage.Headers.To = factory.Endpoint.Address.Uri;
// Create client channel
_client = factory.CreateChannel();
// Begin request
return _client.BeginProcessRequest(requestMessage, asyncCallback, asyncState);
}
public Message EndProcessRequest(IAsyncResult asyncResult)
{
Message message = null;
try
{
message = _client.EndProcessRequest(asyncResult);
}
catch(FaultException faultEx)
{
throw faultEx;
}
catch(Exception ex)
{
ServiceData myServiceData = new ServiceData();
myServiceData.Result = false;
myServiceData.ErrorMessage = ex.Message;
myServiceData.ErrorDetails = ex.Message;
throw new FaultException<ServiceData>(myServiceData, ex.Message);
}
return message;
}
public void Dispose()
{
if (_client != null)
{
var channel = (IClientChannel)_client;
if (channel.State != CommunicationState.Closed)
{
try
{
channel.Close();
}
catch
{
channel.Abort();
}
}
}
}
}
и выполните настройку в файле web.config
<services>
<service name="RoutingService" behaviorConfiguration="JsonRoutingBehave">
<endpoint address="" binding="webHttpBinding" contract="IRoutingService" name="serviceName" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
<client>
<endpoint address="<actual service url here>" binding="webHttpBinding" bindingConfiguration ="JsonBinding" contract="*" name="endpointName">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp helpEnabled="true"
automaticFormatSelectionEnabled="true"
faultExceptionEnabled="true"/>
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="JsonRoutingBehave">
<serviceDebug includeExceptionDetailInFaults="true" />
<routing filterTableName="ftable"/>
</behavior>
</serviceBehaviors>
</behaviors>
<routing>
<filters>
<filter name="all" filterType="MatchAll"/>
</filters>
<filterTables>
<filterTable name="ftable">
<add filterName="all" endpointName="endpointName"/>
</filterTable>
</filterTables>
</routing>
<bindings>
<webHttpBinding>
<binding name="JsonBinding" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" allowCookies="true" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
</bindings>