【发布时间】:2019-05-28 18:00:27
【问题描述】:
我一直在尝试使用非标准 HTTPS 端口在我的 IIS 服务器上发布 WCF Web 服务。只有在身份验证后才能访问服务器(通过基本身份验证)。我为测试目的创建的 Web 服务是您在 Visual Studio 中创建 WCF Service Application 时默认获得的基础项目。我所做的唯一修改是在web.config 文件中:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="SoapApi.Service1">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="secureHttpBinding"
contract="SoapApi.IService1"/>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
在本地文件系统上发布服务并配置 IIS 之后。从本地 PC 上的浏览器进行身份验证后,我能够访问服务器上的 WSDL 文件。但是,如果我尝试使用 Visual Studio 中的 Configure WCF Web Service Reference 向导将服务添加到简单的客户端应用程序,则会收到以下错误消息:
Metadata contains a reference that cannot be resolved:'http://<host>:<port><path>?wsdl'.
以及完整的错误信息:
An error occurred while attempting to find services at 'http://<host>:<port><path>?wsdl'. The remote server returned an error: (403) Forbidden.
既然这个错误表明我没有访问权限,我想为什么不关闭身份验证并尝试它是否有效。我在 IIS 中激活了网站的匿名访问并停用了基本身份验证。
此外,我更改了web.config 文件中的以下段落:
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
我仍然可以从我的浏览器访问 WSDL 文件,但是在将服务引用添加到客户端时仍然遇到相同的错误。如果我通过dotnet-svcutil http://<host>:<port><path>?wsdl 测试它,也会发生同样的情况@
如果我尝试在本地添加服务引用,一切正常,没有任何问题。
其他信息:
- 我已经安装了
.NET Framework 4.6,它是WCF HTTP Activation处理程序。 - 我将权限
IIS_IUSRS添加到包含服务的文件夹中。
关于为什么会发生这种情况以及我可以做些什么来解决这个问题的任何想法?
【问题讨论】:
标签: visual-studio wcf iis wsdl