views:

28

answers:

2

Hi all

I need to configure and query a Cisco router from my .NET application, and I need to do it by way of the Cisco WSMA web services interface.

These services are exposed over HTTP (in my case), and use SOAP 1.2 to enclose requests and responses (schema here). So a call may look like this (example from the Wikipedia article):

<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"&gt; 
  <SOAP:Body> 
    <request correlator="4.7" xmlns="urn:cisco:wsma-config" > 
      <configApply details="all"> 
        <config-data> 
          <cli-config-data> 
            <cmd>access-list 1 permit any</cmd>
            <cmd>ip hst foo 1.1.1.1</cmd>
            <cmd>no cns exec 80 </cmd>
          </cli-config-data>
        </config-data>
      </configApply>
    </request>
  </SOAP:Body>
</SOAP:Envelope>]]>]]>

This is all very cool, of course (certainly beats mucking around with telnet - AND it supports atomic transactions - all succeed or all fail - whereas CLI doesn't).

But up until now, I have been living in a comfortable .NET bubble where web services emit WSDL and I can build proxies in the client and things just work (or not ;-). There is no WSDL available, as far as I have been able to work out, and I don't quite see how to go about this.

  • How do I configure WCF for something like this (set up a basicHttpBinding and a client endpoint)?
  • How do I turn these schemas into contracts? By hand?
  • Can SvcUtil do anything useful with those schemas?
  • If I can create contracts somehow, does that mean I can generate proxies to work with, or will I have to work at a lower level?

I know as soon as I get some momentum, I'll get along fine. Can someone with similar experiences be a star and give me a few bullet points on how to go about this? Perhaps point me to some relevant blog post?

+1  A: 

One method that may work is to convert the XSD's that you have to a WSDL, for example by using this XSLT tool

Shiraz Bhaiji
That could work. In this case, Ladislav's suggestion seems to fit best.
Tor Haugen
+2  A: 

Use XSD.exe to generate classes from provided XSDs. It seams that each file contains XSD for request, response and error, so each file represents single operation. Create service contract like

// ConfigXSDError, ConfigXSDRequests and ConfigXSDResponse are types generated by XSD 

// Message contracts are needed to avoid wrapping
[MessageContract(IsWrapped = false)]
public class ConfigResponse
{
  [MessageBodyMember]
  [XmlElement("response")]
  public ConfigXSDResponse Response { get; set; }
}

[MessageContract(IsWrapped = false)]
public class ConfigRequest
{
  [MessageBodyMember]
  [XmlElement("request")]
  public ConfigXSDRequest Request { get; set; }
}

// Other message contracts

// Service contract uses XmlSerializer instead of DataContractSerializer

[ServiceContract]
[XmlSerializerFormat(SupportFaults = true)]
public interface ICiscoRouter
{
  [OperationContract]
  [FaultContract(typeof(ConfigXSDError))]
  ConfigResponse Config(ConfigRequest request);

  // Other methods
}

Use ChannelFactory to create proxy for the service.

Ladislav Mrnka
Thanks Ladislav, that was just what I needed!
Tor Haugen