Search code examples
wcfmetadataproxy-classessiteminder

Exposing WCF metadata on a SiteMinder protected site


This might be a really stupid question, but I've been unable to figure out a solution. I have a WCF service hosted on a site that uses SiteMinder authentication. The authentication relies on a cookie in the client request.The problem is that when I try to generate a proxy class using svcutil, the operation fails because when svcutill tries to get the metadata, it obviously doesn't add the SiteMinder cookie to its request.I was therefore wondering if there was a simple way to generate the WCF service proxy class programatically.


Solution

  • If you have access to the compiled service DLL file, you can use the SvcUtil command line utility to generate the WSDL and associated XSDs for the data contracts. The main wrinkle with this approach is you'll need to add the name of the XSD file generated by SvcUtil in each xsd:import element in the schemaLocation attribute value.

    Below are samples of modified xsd:import elements. For the "http://tempuri.org/" namespace, I added the schemaLocation attribute with the value of "tempuri.org.xsd" to let the Add Service Reference process know to look for that file in the same folder as the WSDL file. If your WSDL uses wsdl:import instead, add a location attribute instead of a schemaLocation attribute. This related question and answer should give a good start.

      <wsdl:types>
        <xsd:schema targetNamespace="http://tempuri.org/Imports">
          <xsd:import namespace="http://tempuri.org/" schemaLocation="tempuri.org.xsd" />
          <xsd:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" schemaLocation="schemas.microsoft.com.2003.10.Serialization.xsd" />
        </xsd:schema>
      </wsdl:types>
    

    EDIT:

    Generating the client code using the compiled service DLL requires a two step process. SvcUtil needs the service WSDL to generate the client. It cannot directly use the compiled DLL.

    First generate the WSDL using the DLL that contains the ServiceContract. I think you can use the service implementation file if the service contract DLL is also in the same folder.

    cd "\Path\To\Your\Service\DLLs"
    svcutil YourService.DLL
    

    This will create several files depending on your service structure. There'll be one .WSDL file and several .XSD files. Edit these files as shown above.

    Lastly, either use the Visual Studio Add Service Reference dialog to select the edited .WSDL file (just enter the full path and file name) to generate the client code or use SvcUtil as follows:

    svcutil *.wsdl *.xsd /language:C#