0

I have a WCF Router in a console application that works well, but I need to host this in Azure. As a result I have been asked to make this as a web app so it can be hosted as an app service.

The Router that I have uses this as a config right now

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
  multipleSiteBindingsEnabled="true" />
<services>
  <service name="System.ServiceModel.Routing.RoutingService">
    <endpoint
              binding="basicHttpBinding"
              contract="System.ServiceModel.Routing.IRequestReplyRouter"
              name="proposalRouter" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:54636/routingService"/>

      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceDebug includeExceptionDetailInFaults="true" />
      <routing filterTableName="proposalRoutingTableVersion"/>
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding
      name="TestBinding"
      allowCookies="True"
      closeTimeout="00:04:00"
      openTimeout="00:00:10"
      receiveTimeout="00:05:00"
      sendTimeout="00:05:00"
      maxReceivedMessageSize="15728640">
      <security mode="None" />
    </binding>
  </basicHttpBinding>
</bindings>
<routing>
  <namespaceTable>
    <add prefix="xxx" namespace="xxxxx"/>
  </namespaceTable>
  <filters>
    <filter name="version_0_9"
            filterType="Custom"
            filterData="0.9"
            customType="RouterService.Asp.VersionFilter, RouterService.Asp"
    />
    <filter name="version_1_0"
            filterType="Custom"
            filterData="1.0"
            customType="RouterService.Asp.VersionFilter, RouterService.Asp"
    />
  </filters>
  <filterTables>
    <filterTable name="proposalRoutingTableVersion">
      <!--<add filterName="version_0_9" endpointName="version_0_9"/>
      <add filterName="version_1_0" endpointName="version_1_0"/>
      -->
      <!-- Acts as the else clause-->
      <!--
      <add filterName="noVersion" endpointName="version_0_9"/>-->

      <add filterName="version_0_9" endpointName="version_0_9" priority="1"/>
      <add filterName="version_1_0" endpointName="version_1_0" priority="0"/>

    </filterTable>
  </filterTables>
</routing>

<client>
  <endpoint address="http://localhost:63690/ProposalService_1_00.svc"
            binding="basicHttpBinding"
            contract="*"
            name="version_1_0"/>

  <!--<endpoint address="http://localhost:63690/ProposalService.svc"
            binding="basicHttpBinding"
            contract="*"
            name="version_0_9"/>-->

  <!--<endpoint address="http://localhost:63253/ProposalService.svc"
            binding="basicHttpBinding"
            contract="*"
            name="version_0_9"/>-->
</client>

</system.serviceModel>

This drops into the version filter

public class VersionFilter : MessageFilter
{
    private string _filterData;
    private readonly XNamespace _xmlnsa = "xxxxxx";

    public VersionFilter(string filterData)
    {
        _filterData = filterData;
    }

    public override bool Match(MessageBuffer buffer)
    {
        throw new NotImplementedException();
    }

    public override bool Match(Message message)
    {
        XDocument doc = XDocument.Parse(message.ToString());

        var version = (from xml in doc.Descendants(_xmlnsa + "getProposal")
                       select xml.Attribute("version")).FirstOrDefault();

        return _filterData == version.Value.ToString(); ;
    }
}

And then gives the true or false response, then does not hit either of my WebService end points that I am trying to hit.

I have looked in a variety of places for answers on this, but everywhere I have looked show the same \ similar code to what I have in place.

Some suggestions talk about decorating my enums with [EnumMember], so went and added this to every enum. This didnt help.

I have changed from basic to wsHttpBinding, this also did not help, and then I got a 415 error.

I cannot see why \ how changing from a console app to an ASP.Net WCF Application, and an ASP.Net Web Application would cause this to stop working.

In the interested of not missing anything out that I am not seeing this is the response received.

<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <s:Fault>
            <faultcode
                xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault
            </faultcode>
            <faultstring xml:lang="en-GB">An unexpected failure occurred. Applications should not attempt to handle this error. For diagnostic purposes, this English message is associated with the failure: 'Shouldn't allocate SessionChannels if session-less and impersonating'.</faultstring>
            <detail>
                <ExceptionDetail
                    xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel"
                    xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                    <HelpLink i:nil="true"/>
                    <InnerException i:nil="true"/>
                    <Message>An unexpected failure occurred. Applications should not attempt to handle this error. For diagnostic purposes, this English message is associated with the failure: 'Shouldn't allocate SessionChannels if session-less and impersonating'.</Message>
                    <StackTrace>   at System.Runtime.Fx.AssertAndThrow(String description)&#xD;
   at System.ServiceModel.Routing.RoutingChannelExtension.get_SessionChannels()&#xD;
   at System.ServiceModel.Routing.RoutingService.GetOrCreateClient[TContract](RoutingEndpointTrait endpointTrait, Boolean impersonating)&#xD;
   at System.ServiceModel.Routing.ProcessRequestAsyncResult`1.StartProcessing()&#xD;
   at System.ServiceModel.Routing.ProcessRequestAsyncResult`1..ctor(RoutingService service, Message message, AsyncCallback callback, Object state)&#xD;
   at System.ServiceModel.Routing.RoutingService.BeginProcessRequest[TContract](Message message, AsyncCallback callback, Object state)&#xD;
   at System.ServiceModel.Routing.RoutingService.System.ServiceModel.Routing.IRequestReplyRouter.BeginProcessRequest(Message message, AsyncCallback callback, Object state)&#xD;
   at AsyncInvokeBeginBeginProcessRequest(Object , Object[] , AsyncCallback , Object )&#xD;
   at System.ServiceModel.Dispatcher.AsyncMethodInvoker.InvokeBegin(Object instance, Object[] inputs, AsyncCallback callback, Object state)&#xD;
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace>
                    <Type>System.Runtime.Fx+InternalException</Type>
                </ExceptionDetail>
            </detail>
        </s:Fault>
    </s:Body>
</s:Envelope>

I have tried enabling log, but dont get as far as writing one so not sure what else to try or do.

Simon Price
  • 3,011
  • 3
  • 34
  • 98
  • Are you running on same machine as console or different machine? Are you running service a Admin? The exception is caused by "'Shouldn't allocate SessionChannels if session-less and impersonating".(see : https://stackoverflow.com/questions/16826874/receiving-an-error-using-url-routing-with-built-in-wcf-router-service). What credentials would you be using to make connection? A client connecting to the service would be using a GUEST credentials which isn't sufficient to make the connection. So do you want to make connection as an Admin? – jdweng Jun 26 '20 at 15:47
  • yes, currently all in the same machine – Simon Price Jun 26 '20 at 15:48
  • and yes, everything running as admin – Simon Price Jun 26 '20 at 15:48
  • no credentials required as such at the moment either – Simon Price Jun 26 '20 at 15:49
  • Additionally I had seen this link previously too which was also of no assistance. – Simon Price Jun 26 '20 at 15:55
  • The user credentials are being used when running as a console application. When you connect from a client to Azure you are running as GUEST and do not have privilege. When connecting from client and service is running as ADMIN it also works. So what do you want to do? – jdweng Jun 26 '20 at 16:02
  • so, if all are currently running in the same IIS Express or even IIS instnace would they not be carrying the right credentials? – Simon Price Jun 26 '20 at 16:04
  • What credentials should they be using? If I do not have an account on the server and make a web connection what credentials should be used? Do you expect everybody who uses the service have an account on the server? – jdweng Jun 26 '20 at 16:12
  • No I dont expect that, I was expecting a straight pass through for the moment – Simon Price Jun 26 '20 at 16:15
  • looking at the example provided and the custom binding too there are a number of elements \ attributs that vs is saying is not allowed – Simon Price Jun 26 '20 at 16:24
  • You have three choices 1) Run as Admin 2) Have users login 3) Use Network Credentials of user. The default is Guest. – jdweng Jun 26 '20 at 16:26
  • Run as admin would be my preferred choice at the moment – Simon Price Jun 26 '20 at 16:30
  • this is, however going to be hosted in an Azure App Service so not sure which method is the best method – Simon Price Jun 26 '20 at 16:31
  • What example? Which elements/attributes not allowed? You have to choose BEST method. Is Admin acceptable? I do not know your security requirements. – jdweng Jun 26 '20 at 16:32
  • I had put the elements in to a custom binding, which now see they should have been in basichttpbinding – Simon Price Jun 26 '20 at 16:39
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/216739/discussion-between-simon-price-and-jdweng). – Simon Price Jun 26 '20 at 16:39

1 Answers1

0

So, it turns out that this line in the web.config file was the issue

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                           multipleSiteBindingsEnabled="true" />

removing this line as suggested here https://seroter.com/2010/09/19/lesson-learned-wcf-routing-service-and-the-basichttpbinding/ was the solution to the problem.

Simon Price
  • 3,011
  • 3
  • 34
  • 98