views:

42

answers:

2

Hi

This post regards the last hurdle in completing my task of communicating with a Cisco router via the Web Services Management Agent (WSMA), as described here and here. You will not have to read those posts to understand my current question, though.

The problem is this: I have build service and message contracts to match the router's web services, and configured a basicHttpBinding and an endpoint. And using a channel factory, I am now almost, but not quite, communicating successfully with the router.

I keep getting a SOAP fault in return, stating that "An expected XML tag or sequence is missing". Using WCF tracing, fiddler and debugging on the router, and manually posting messages over HTTP, I have finally figured out what's going on.

The WSMA agent on the router expects the SOAP message payload in the HTTP request to include an XML declaration. And WCF isn't sending one. As simple as that.

So my question is: How can I make WCF, using a basicHttpBinding, include an XML declaration in the message?

For reference, my binding configuration looks like this:

<basicHttpBinding>
  <binding name="BasicHttpBinding_IWsmaService" messageEncoding="Text" textEncoding="UTF-8" allowCookies="false">
    <security mode="TransportCredentialOnly">
      <transport clientCredentialType="Basic" proxyCredentialType="None" realm="level_15" />
    </security>
  </binding>
</basicHttpBinding>

(in case you wonder - yes, I am aware that I'm sending clear-text credentials over an unencrypted transport)

A: 

You will have to create custom encoder. Check WCF samples. Provided sample shows how to create new encoder with composition of existing one. You will use TextMessageEncodingBindingElement to create inner MessageEncoder. Your WriteMessage implementatoin will write XML declaration and than call inner encoder to write serialized message.

You will also need to wrap your new encoder in custom binding element and use it in custom binding together with HttpTransportBindingElement.

Ladislav Mrnka
Yup. More work than I'd hoped for, but it seems the only way. And it worked very well. Thanks.
Tor Haugen
+1  A: 

That's what you need to read this article in MS Library ms751486.aspx

However according to rfc3470:

4.4 XML Declarations ... In some uses of XML as an embedded protocol element, the XML used is a small fragment in a larger context, where the XML version is fixed at "1.0" and the character encoding is known to be "UTF-8". In those cases, an XML declaration might add extra overhead. ... Protocol specifications must be clear about use of XML declarations. XML [8] notes that "XML documents should begin with an XML declaration which specifies the version of XML being used." In general, an XML declaration should be encouraged ("SHOULD be present") and must always be allowed ("MAY be sent"). An XML declaration should be required in cases where, if allowed, the character encoding is anything other than UTF-8 or UTF-16.

I can't find in SOAP 1.1 SPEC clear information about use of XML declarations. Does anybody else can do this?

eject