在Azure应用程序网关后面托管WCF服务时如何获取正确的WSDL URL?

时间:2019-02-10 15:48:54

标签: azure wcf wsdl azure-web-sites azure-application-gateway

我们正在将服务从本地迁移到Azure,现在我们正在托管旧版WCF服务和Azure App Service。为了使其与现有客户端向后兼容,需要通过{domainNameHere}.com/services使用它。

还应该通过同一域访问其他服务,例如{domainNameHere}.com/api。我们已经设置了一个Azure应用程序网关,以根据请求路径将请求路由到不同的App Services,并设置{domainNameHere}.com指向应用程序网关IP。

这对于WCF服务以外的所有服务都适用。可以在浏览器中的https://{domainNameHere}.com/services/exports.svc上访问它,但是该页面上的WSDL URI显示azurewebsites.net URI,而不是我们的自定义域。客户端尝试访问服务时,会出现以下错误:

System.ServiceModel.EndpointNotFoundException:
'There was no endpoint listening at https://{domainNameHere}.com/services/export.svc
that could accept the message. This is often caused by an incorrect address or SOAP
action. See InnerException, if present, for more details.'

Inner Exception
WebException: The remote server returned an error: (404) Not Found.

我们尝试在WCF配置中使用useRequestHeadersForMetadataAddress无济于事。

这是WCF配置,所有内容均在代码中。 endpoint URI为https://{domainNameHere}.com/services/exports.svc

public static void Configure<T>(ServiceConfiguration config, Uri endpoint) where T : class
{
    // Configure service behavior
    config.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true, HttpsGetEnabled = true });
    config.Description.Behaviors.Add(new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });

    var serviceCredential = config.Description.Behaviors.Find<ServiceCredentials>();
    if (serviceCredential == null)
    {
        serviceCredential = new ServiceCredentials();
        config.Description.Behaviors.Add(serviceCredential);
    }

    serviceCredential.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
    serviceCredential.UserNameAuthentication.CustomUserNamePasswordValidator = new CredentialsValidator();

    config.AddServiceEndpoint(typeof(T), GetBinding(), endpoint);
}

1 个答案:

答案 0 :(得分:0)

我终于明白了。应用程序网关使用HTTP向WCF服务发出请求,但是WCF服务仅在HTTPS上答复。我更新了Application Gateway以使用HTTPS发出请求后,它就按预期运行了。