如何使用 REST/SOAP 端点发布 WCF 4.0 服务的 WSDL

发布于 2024-11-30 12:44:36 字数 2650 浏览 1 评论 0原文

我正在创建一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

邮友 2024-12-07 12:44:36

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

时常饿 2024-12-07 12:44:36

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

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

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

You should be able to get the WSDL by using the mex URL directly from the browser:

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

The WcfTestClient is almost certainly doing that to retrieve the WSDL so it can generate the proxy to the service.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文