【问题标题】:How to publish WSDL for WCF 4.0 service with REST/SOAP endpoints如何使用 REST/SOAP 端点为 WCF 4.0 服务发布 WSDL
【发布时间】:2011-08-19 09:30:33
【问题描述】:

我正在创建一个带有 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?wsdlhttp://localhost:1313/ServiceTest/VehicleService/soap?wsdl 找到 WSDL

如果我想为 SOAP 端点发布 WSDL,是否需要添加 .svc 文件?

【问题讨论】:

    标签: wcf web-services rest soap wsdl


    【解决方案1】:

    我已经设法让 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

    【讨论】:

      【解决方案2】:

      您应该能够直接从浏览器使用 mex URL 获取 WSDL:

      http://localhost:1313/ServiceTest/VehicleService/mex
      

      几乎可以肯定,WcfTestClient 这样做是为了检索 WSDL,以便它可以生成服务的代理。

      【讨论】:

        猜你喜欢
        • 2010-09-16
        • 2011-12-11
        • 2011-07-21
        • 1970-01-01
        • 2010-12-16
        • 2013-01-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多