根据环境更改WCF服务的WSDL

问题描述 投票:0回答:1

我在本地计算机上具有WCF服务和.net客户端。我已经为客户端生成了wsdl。它有一堆文件,例如.svcinfo, .wsdl, .xsd, .svcmap, .cs。一些文件具有服务的地址https://localhost:12345/foo/bar.svc

最终,将服务和客户端部署到测试中,然后再部署到生产中。那时我需要为客户端重新生成wsdl以便在.svcinfo, .wsdl, .xsd, .svcmap, .cs文件中反映正确的网址吗?还是更改客户端配置文件中的endpoint地址就足够了?

.net wcf wsdl wcf-endpoint
1个回答
0
投票

您绝对不需要这样做。我们通常通过其元数据端点公开有关WCF服务的元数据信息。然后,客户端可以通过添加服务引用来生成客户端代理类,并且代理类可以实现对服务的调用。

<services>
      <service name="WcfService1.Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WcfService1.IService1"></endpoint>
        <!--metadata service endpoint-->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!--Enable service metadata publish-->
          <serviceMetadata/>
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
</behaviors>

客户端。enter image description here您也可以选择以HTTP / https的形式发布服务数据,只需配置以下属性即可。

  <!--Enable service metadata publish-->
  <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>

通过这种方式,客户端可以直接下载WSDL / SingleWSDL文件,从而手动生成客户端代理类。enter image description here请随时告诉我是否有什么我可以帮助的。

© www.soinside.com 2019 - 2024. All rights reserved.