Supply a different endpoint address in the WSDL of

2020-07-14 10:15发布

问题:

I have a fairly standard WCF service (hosted on IIS7) which generates a fairly standard WSDL when queried with ?wsdl:

<wsdl:definitions>
  <!-- ... -->
  <wsdl:service>
    <wsdl:port>
      <soap:address location="https://machine/virtual_dir/servicename.svc"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

(boring bits omitted)

I'm after a quick 'n dirty way to change the address given in this generated WSDL to something completely different, for example:

https://othermachine/other_dir/other_service.svc

What is the easiest way of doing this?

回答1:

There are several approaches you could look at:

  • WCF supports a lot of extensibility points, and the generation of the WSDL is one of those. You could write your own custom WSDL generator and plug it into WCF

  • the probably easier way would be to generate the WSDL you have, then tweak it manually, and put that WSDL file somewhere and configure it to be served up (instead of WCF generating the WSDL at runtime, when requested to do so)

You can configure option #2 with the <serviceMetadata> behavior:

<behaviors>
   <serviceBehaviors>
       <behavior name="StaticMetadata">
           <serviceMetadata httpGetEnabled="true"
                externalMetadataLocation="(url path to your static WSDL file)" />
       </behavior>
   </serviceBehaviors>
</behaviors>

If you do this, and your service uses this service behavior, any requests for the WSDL or for MEX data will be routed to that static WSDL you've provided, instead of using the auto-generated WSDL that WCF would normally supply.