如何使用 REST/SOAP 端点发布 WCF 4.0 服务的 WSDL
我正在创建一个带有 REST 和 SOAP 端点的 WCF4 服务,该服务将托管在 IIS 7.5 中。 我使用 WCF4 REST 模板作为示例。 不过,到目前为止,我对我的设置有一些疑问。
这是我的 webconfig,
<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 文件?
I'm creating a WCF4 service with REST and SOAP endpoints to be hosted in IIS 7.5.
I have used the WCF4 REST template as an example.
However I have a few questions regarding my setup so far.
Here's my webconfig
<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>
I have removed the standardEndpoints section and added endpoints of my own.
There are no .svc files as I've set the routes in the global.asax as shown below
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("VehicleService", new WebServiceHostFactory(), typeof(VehicleService)));
}
The help pages can be accessed via http://localhost:1313/ServiceTest/VehicleService/help
I've also used the WCF Test Client to access http://localhost:1313/ServiceTest/VehicleService/mex
which shows the metadata for the SOAP endpoint
But how do I retrieve the WSDL of the service?
With an svc file I can find the wsdl at http://localhost:1313/ServiceTest/VehicleService.svc?wsdl However I do not have a .svc file.
And neither can I find the WSDL at http://localhost:1313/ServiceTest/VehicleService?wsdl or http://localhost:1313/ServiceTest/VehicleService/soap?wsdl
Do I need to add a .svc file if I want to publish WSDL for the SOAP endpoint?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经设法让 WSDL 在 http://localhost:1313/ServiceTest/VehicleService?wsdl。
解决方案是在 global.asax 中使用新的 ServiceHostFactory 而不是新的 WebServiceHostFactory。
使用 WebServiceHostFactory,您将失去 WSDL 功能。
可以在这里找到类似的问题:
ServiceRoute + WebServiceHostFactory 会终止 WSDL 生成吗?如何使用 ?wsdl 创建无扩展的 WCF 服务
I have managed to get the WSDL working at http://localhost:1313/ServiceTest/VehicleService?wsdl.
The solution was using new ServiceHostFactory instead of new WebServiceHostFactory in the global.asax.
With WebServiceHostFactory you lose the WSDL functionality.
A similar question can be found here:
ServiceRoute + WebServiceHostFactory kills WSDL generation? How to create extensionless WCF service with ?wsdl
您应该能够直接从浏览器使用 mex URL 来获取 WSDL:
WcfTestClient 几乎肯定会这样做来检索 WSDL,以便它可以生成服务的代理。
You should be able to get the WSDL by using the mex URL directly from the browser:
The WcfTestClient is almost certainly doing that to retrieve the WSDL so it can generate the proxy to the service.