我正在练习WCF并坚持这种情况。 我的Wcf服务在IISExpress下完美运行(默认为VS2013)。 但是当我在Local IIS下使用相同的内容时,我在WCF测试客户端中遇到了异常。
错误:无法从中获取元数据 http://localhost/WcfService1/Service1.svc如果这是Windows(R) 请访问您的Communication Foundation服务 检查您是否已在指定的位置启用元数据发布 地址。有关启用元数据发布的帮助,请参阅 MSDN文档在 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交流 错误URI:http://localhost/WcfService1/Service1.svc元数据包含 无法解决的引用: ' http://localhost/WcfService1/Service1.svc&#39 ;.远程服务器 返回了意外的响应:(405)方法不允许。遥控器 服务器返回错误:(405)方法不允许.HTTP GET错误URI: http://localhost/WcfService1/Service1.svc发生错误 下载' http://localhost/WcfService1/Service1.svc'。请求 HTTP状态404失败:未找到。
我的网络配置包含元数据交换的端点,行为也是httpGetEnabled为真。
请参阅web.config:
<?xml version="1.0"?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="f:\tfs\wcfservice1\wcfservice1\web_messages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true"
logMessagesAtTransportLevel="true" />
</diagnostics>
<services>
<service behaviorConfiguration="behave" name="WcfService1.Service1">
<endpoint address="WcfService1.Service1" binding="basicHttpBinding" name="basicHttp"
contract="WcfService1.IService1" />
<endpoint binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/WcfService1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="behave">
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
我检查了其他WCF问题。但无法找到答案。 提前谢谢。
当我使用本地IIS时,我可以点击网址 http://localhost/wcfservice1/ 它显示了该目录中的所有文件。 但是当我点击Service1.svc时,它会显示IIS错误页面。
HTTP错误404.3 - 未找到您请求的页面不能 由于扩展配置而提供服务。如果页面是 脚本,添加处理程序。如果要下载文件,请添加MIME 地图。
答案 0 :(得分:3)
您需要在IIS管理器中为您的站点启用WCF,请参阅:https://blogs.msdn.microsoft.com/blambert/2009/02/13/how-to-enable-iis7asp-net-and-wcf-http-activation/
为IIS启用WCF后,您应该可以毫无问题地运行所有内容。
答案 1 :(得分:2)
我解决了问题。 我已打开.Net framework 4.6高级服务&gt; WCF服务&gt; HTTP激活。 现在WCF服务工作正常。
Thanx to gmiley ..你之前的回答让我在那里。