1

我在尝试使用 VS2019 将 WCF 服务(.Net 框架 4.7)部署到 Azure Web App 时遇到了这个问题。我无法在浏览器中访问该服务。这是链接

我已经在 Azure 应用服务中将 CORS 设置为 *。

下面是服务配置。

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

服务合同

public class Service1 : IService1
{
    public string GetData(int value)
    {
        return string.Format("You entered: {0}", value);
    }

    public CompositeType GetDataUsingDataContract(CompositeType composite)
    {
        if (composite == null)
        {
            throw new ArgumentNullException("composite");
        }
        if (composite.BoolValue)
        {
            composite.StringValue += "Suffix";
        }
        return composite;
    }
}
4

1 回答 1

0

在本地 IIS 服务器和 Azure 应用服务中托管服务没有区别。
从您的链接中,我发现您尝试访问https://baseaddress/IService1.svc

https://wcfservicedemo20191121055716.azurewebsites.net/IService1.svc

这是非法的。默认的 WCF 项目仅包含 Service.svc 文件,其中包含服务工厂的定义标记。它是 WCF 基地址的一部分。
因此,为了访问起始页/WSDL,我们应该使用服务工厂文件的名称。

https://baseaddress/Service.svc

如果有什么我可以帮忙的,请随时告诉我。

于 2019-11-26T07:59:54.753 回答