Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supply a different endpoint address in the WSDL of a WCF web service

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?

like image 401
Justin Avatar asked Feb 22 '11 04:02

Justin


People also ask

Can WCF service have multiple endpoints?

As demonstrated in the Multiple Endpoints sample, a service can host multiple endpoints, each with different addresses and possibly also different bindings. This sample shows that it is possible to host multiple endpoints at the same address.

What is the endpoint URL in a WSDL?

The URL prefix format is protocol://host_name:port_number , for example, http:// myHost :9045 . The actual endpoint URL that is contained in a published WSDL file consists of the prefix followed by the module's context-root and the web service url-pattern, for example, http:// myHost :9045/services/ myService .

What is endpoint address in WCF?

In WCF, an EndpointAddress models an endpoint reference (EPR) as defined in the WS-Addressing standard. The address URI for most transports has four parts. For example, this URI, http://www.fabrikam.com:322/mathservice.svc/secureEndpoint has the following four parts: Scheme: http: Machine: www.fabrikam.com.

How many endpoints can a WCF Service have?

The service configuration has been modified to define two endpoints that support the ICalculator contract, but each at a different address using a different binding.


1 Answers

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.

like image 190
marc_s Avatar answered Nov 15 '22 09:11

marc_s