我正在创建一个带有 REST 和 SOAP 端点的 WCF4 服务,以托管在 IIS 7.5 中。 我以 WCF4 REST 模板为例。 但是,到目前为止,我对我的设置有一些疑问。
这是我的网络配置
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<behaviors>
<endpointBehaviors>
<behavior name="REST">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MEXGET">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MEXGET" name="Project.WebService.VehicleService">
<endpoint
address=""
behaviorConfiguration="REST"
binding="webHttpBinding"
contract="Project.WebService.IVehicleService" />
<endpoint
address="soap"
binding="basicHttpBinding"
contract="Project.WebService.IVehicleService" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
我删除了 standardEndpoints 部分并添加了我自己的端点。 没有 .svc 文件,因为我已经在 global.asax 中设置了路由,如下所示
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("VehicleService", new WebServiceHostFactory(), typeof(VehicleService)));
}
可以通过 http://localhost:1313/ServiceTest/VehicleService/help 访问帮助页面
我还使用 WCF 测试客户端访问 http://localhost:1313/ServiceTest/VehicleService/mex 显示 SOAP 端点的元数据
但是如何检索服务的 WSDL?
通过 svc 文件,我可以在 http://localhost:1313/ServiceTest/VehicleService.svc?wsdl 找到 wsdl但是我没有 .svc 文件。 我也无法在 http://localhost:1313/ServiceTest/VehicleService?wsdl 找到 WSDL或 http://localhost:1313/ServiceTest/VehicleService/soap?wsdl
如果我想为 SOAP 端点发布 WSDL,是否需要添加 .svc 文件?
最佳答案
我已经设法让 WSDL 在 http://localhost:1313/ServiceTest/VehicleService?wsdl 工作. 解决方案是在 global.asax 中使用新的 ServiceHostFactory 而不是新的 WebServiceHostFactory。 使用 WebServiceHostFactory,您将失去 WSDL 功能。
类似的问题可以在这里找到: ServiceRoute + WebServiceHostFactory kills WSDL generation? How to create extensionless WCF service with ?wsdl
关于wcf - 如何使用 REST/SOAP 端点为 WCF 4.0 服务发布 WSDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7119618/