How to configure Yarp Reverse Proxy between clients and CoreWCF Service (Azure Container app)

391 Views Asked by At

I have a CoreWCF Service hosted as an Azure container app, I need to add a reverse proxy between clients and service. I tried using Azure Application Gateway but without success, I keep getting Bad Request error.

I found a microsoft library called YARP, so I created and ASP.net project, installed and configured the library Yarp.ReverseProxy.

Here is my configuration:

Program.cs

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddReverseProxy()
    .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));

var app = builder.Build();
app.MapReverseProxy();
app.Run();

appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "ReverseProxy": {
    "Routes": {
      "route1": {
        "ClusterId": "cluster1",
        "Match": {
          "Path": "{**catch-all}"
        }
      }
    },
    "Clusters": {
      "cluster1": {
        "Destinations": {
          "destination1": {
            "Address": "https://<My_CoreWCF_Azure_Container_Url>"
          }
        }
      }
    }
  }
}

If I try accessing the CoreWCF Service, through the proxy url, using the browser, the proxy works fine and it shows the wsdl page.

I created a console project, that acts as a WCf client, I added the service reference, using <proxy_url>/service.svc. I replaced in all the generated files, the WCFService url with the proxy url. I tried doing some requests, but I keep getting the following error:

Exception Details: System.ServiceModel.ProtocolException: The content type text/xml; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '#content{ FONT-SIZE: 0.7em; PADDING-BOTTOM: 2em; MARGIN-LEFT: 30px}BODY{MARGIN-TOP: 0px; MARGIN-LEFT: 0px; COLOR: #000000; FONT-FAMILY: Verdana; BACKGROUND-COLOR: white}P{MARGIN-TOP: 0px; MARGIN-BOTTOM: 12px; COLOR: #000000; FONT-FAMILY: Verdana}PRE{BORDER-RIGHT: #f0f0e0 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f0f0e0 1px solid; MARGIN-TOP: -5px; PADDING-LEFT: 5px; FONT-SIZE: 1.2em; PADDING-BOTTOM: 5px; BORDER-LEFT: #f0f0e0 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: #f0f0e0 1px solid; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e5e5cc}.heading1{MARGIN-TOP: 0px; PADDING-LEFT: 15px; FONT-WEIGHT: normal; FONT-SIZE: 26px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 3px; MARGIN-LEFT: -30px; WIDTH: 100%; COLOR: #ffffff; PADDING-TOP: 10px; FONT-FAMILY: Tahoma; BACKGROUND-COLOR: #003366}.intro{display: block; font-size: 1em;}TokenService ServiceTokenSer'.

What I'm doing wrong?

Ps. Of course using directly the CoreWCF url, without the proxy, everything works fine and i get the response.

1

There are 1 best solutions below

0
On

I've had this problem with Postman. It is a 415 error, and you need to match the version of SOAP between your client and service. For details, you can check out this post. It may also be because the binding pattern does not fit this type.

Client and service binding mismatch?