I am getting a 400 HTTP error while attempting to use the Sharepoint Query Web Service. My rationale is that this is largely due to a malformed XML which I am unable to wrap my head around as to why:

This is the SOAP request body, can anybody think what is wrong in this ?

<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <Query xmlns="urn:Microsoft.Search">
      <queryXml>"
        <QueryPacket xmlns='urn:Microsoft.Search.Query' Revision='1000'>
          <Query>
            <Context>
              <QueryText language='en-US' type='STRING'>
                Word
              </QueryText>
            </Context>
          </Query>
        </QueryPacket>"
      </queryXml>
    </Query>
  </S:Body>
</S:Envelope>
有帮助吗?

解决方案

The XML is indeed malformed, probably because whatever is parsing it is seeing quotations in between two starting or ending tags, which is illegal.

There are two approaches you could attempt:

  1. Wrap the <queryXml> content with CDATA tags:

    <queryXml><![CDATA[<QueryPacket>...</QueryPacket>]]></queryXml>
    

    Notice that the quotations are gone here; you can put them back if you really need them (though I'm not sure what there purpose would be):

    <queryXml><![CDATA["<QueryPacket>...</QueryPacket>"]]></queryXml>
    
  2. Encode the content so it's not treated as XML:

    <queryXml>&lt;QueryPacket&gt;...&lt;/QueryPacket&gt;</queryXml>
    

    There are several ways of accomplishing the encoding. I'll leave that as an exercise for you, since I don't know how you are building your SOAP request.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top