【发布时间】:2013-01-10 00:03:58
【问题描述】:
我正在编写一个 WCF 服务,尝试在 .NET 4.0 中引入的无文件激活。我试图让服务返回 WSDL,虽然我以非常基本的方式配置了 web.config,但我无法让服务发出 WSDL。 ?wsdl 和 ?singlewsdl 只返回正常的服务页面而不是 WSDL。
我为此使用 .NET 4.5
<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="ods">
<endpoint address="localhost" binding="basicHttpBinding"
contract="co.ods" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"><!--aspNetCompatibilityEnabled="true"-->
<serviceActivations>
<add relativeAddress="ods.svc" service="co.ods" />
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
我认为配置存在问题,但我似乎找不到。
【问题讨论】:
-
我们将
添加到 svc.vb 文件中的每个方法中,并在服务根目录中添加一个 .asmx 文件。通过执行 .asmx?wsdl 生成经典的 wsdl -
我有几个问题。您的服务激活成功了吗?我在查看您的配置时看到的一些事情(只是猜测)。 (1) service name="ods" (尝试给 co.ods) (2) contract="co.ods"。又是 co.ods。您是否写了类型名称而不是合同名称? (3) 你在浏览localhost:port/ods.svc吗?
-
@lcryder WebMethod 用于较旧的 ASMX 服务,而不是 WCF,而且无文件激活的要点是没有 .SVC 文件。
-
@Praburaj (1) 试过这个,但没有成功。我很确定 name="ods" 只是一个供参考的名称,与代码没有联系。唯一的领带是回到路线。 (2) 我写的是类型而不是合同名称,“co.ods”只是为了 SO 而混淆。 (3) 我是正确 URL 的浏览器,我确实得到了“您已创建服务”页面(因此服务激活似乎成功),但 WSDL 操作只是刷新页面而不提供 WSDL。