Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
969 views
in Technique[技术] by (71.8m points)

web services - WCF client does not include XML declaration in HTTP POST message

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...