【发布时间】:2014-06-25 23:13:46
【问题描述】:
我在运行 windows7 的本地计算机上的 IIS 7 中托管了一个简单的 wcf 服务,我尝试使用 winform 访问它,但无论我尝试什么,都会出现相同的错误。我可以通过 http 访问该服务。
在这一点上,我花了一整天的时间试图找出原因,并浏览了关于堆栈溢出主题的大部分帖子。在这一点上,我觉得我缺少一些基本的东西,我们非常感谢专家的任何反馈。
即使你指导我如何调试这个或在哪里寻找确切的原因,这将有很大帮助,因为我在事件日志或失败的请求跟踪中看不到任何有用的东西:(
我已经采取的步骤
- 在 localhost 上设置一个新网站,启用 net.tcp(不带空格)!
- 确保 net.tcp 的所有三个服务都在运行
- 在 webconfig 中禁用安全性(无而不是 windows)。
我的服务详情
namespace WcfService1
{
public class Service1 : IService1
{
public string Echo(string msg)
{
return DateTime.Now.ToString();
}
}
}
网络配置
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="WcfService1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpBinding" contract="WcfService1.IService1" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:820/Service1.svc"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="tcpBinding" portSharingEnabled="true">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="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" />
</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>
完整的错误详情
The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:820/Service1.svc'.
The requested service, 'net.tcp://localhost:820/Service1.svc' could not be activated. See the server's diagnostic trace logs for more information.
If the service is defined in the current solution, try building the solution and adding the service reference again.
【问题讨论】:
-
相当怀疑是不是这样,但您可以尝试取消注释
<protocolMapping>部分并添加<add binding="netTcpBinding" scheme="net.tcp" />。还要查看 IIS 日志和事件查看器,看看那里是否有任何信息。 -
感谢蒂姆的建议,我已经尝试过了,但我要查看 iis 日志,看看是否有任何发现。