与思科WSMA从.NET工作思科、工作、WSMA、NET

2023-09-03 02:57:20 作者:有种爷们叫石头

我需要配置,并从我的.NET应用程序查询一台Cisco路由器,我需要通过思科 WSMA Web服务接口。

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.

这些服务暴露通过HTTP(在我的情况),并使用SOAP 1.2附上请求和响应(架构的这里)。因此,一个电话可能是这样(例如从维基百科文章):

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/"> 
  <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>]]>]]>

这是所有非常冷静,当然(当然比通过telnet摆弄周围 - 它支持原子事务 - 全部成功,要么全部失败 - 而CLI不)。

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).

不过,到现在为止,我一直生活在一个舒适的.NET泡沫,其中Web服务发出WSDL,我可以在客户端建立代理和事物只是工作(或不;-)。没有WSDL可用,据我已经能够工作了,我不太看如何去这一点。

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.

如何配置WCF这样的事情(设置了basicHttpBinding的和客户终端)? 如何把这些模式了合同?通过手? 可以SvcUtil工具做任何与这些模式?有用 如果我能以某种方式建立的合同,这是否意味着我可以生成代理的工作,否则我将不得不工作在一个较低的水平?

我马上知道我得到一些动力,我会相处得很好。有人用类似的经历能成为明星,并给我如何去这几个要点?也许我指向一些相关的博客文章?

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?

推荐答案

使用XSD.EXE来生成提供XSD的类。它接缝,每个文件包含的XSD用于请求,应答和出错,因此每个文件重新presents单个操作。像创建服务合同

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
}

使用的ChannelFactory 以创建服务代理。