Modifying Spell Check for SharePoint Server 2007, Page 2
In the code, create a StringBuilder that contains the SOAP call to the WebService. The SOAP envelope is directly added by using the following syntax:
static string EnvelopeSoap = @"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <soap:Body></soap:Body> </soap:Envelope>";
Then, immediately before closing the envelope, add the XML query with the following syntax:
static string MyQuery = @"<SpellCheck xmlns= 'http://schemas.microsoft.com/sharepoint/publishing/spelling/'> <chunksToSpell> <string>This rou</string> <string> has an error </string> </chunksToSpell> <declaredLanguage>1033</declaredLanguage> <useLad>false</useLad> </SpellCheck>";
There are two strings in the query that need to be adjusted, namely "This rou" and "has an error", the Language Identifier is declared (1033) and the MOSS Language Identifier must be blocked with the code; useLead=false. As stated earlier, at this point you need to define the spell check Language Identifier if you are using a language other than English.
After the creation of the envelope and the query in a string, they are converted to a XmlDocument that can be used in the service call. The object "myQueryWeb" (of the "HttpWebRequest" type) is created using as input parameter the URL of the spell check WebService:
static string UrlChequerWS = "http[s]://ServerName/_vti_bin/SpellCheck.asmx";
The object receives the default credentials of the user, the content type, the type of the method to be used, and finally, the form to send the envelope. The SOAP action type is added to the header in the following manner:
static string AccionSoap = "http://schemas.microsoft.com/sharepoint/publishing/ spelling/SpellCheck";
With this action, the envelope is assigned to the WebService call and using the interface, IAsyncResult, the anticipated result is asynchronous; this avoids a delay in the functioning of SharePoint while awaiting the response.
Finally, the call to the WebService is executed and the results come back in the form of a "WebResponse" object that is converted to a "StreamReader" that needs to be interpreted; the final result is a XML string, "ResponseSoap". The response of the example is in the form:
<?xml version="1.0" encoding="utf-8" ?> - <soap:Envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/ envelope/" xmlns:xsi="http://www.w3.org/2001/ XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> - <soap:Body> - <SpellCheckResponse xmlns="http://schemas.microsoft.com/sharepoint/ publishing/spelling/"> - <SpellCheckResult> <errorCode>Ok</errorCode> <detectedLanguage>1033</detectedLanguage> - <spellingErrors> - <SpellingErrors> <chunkIndex>0</chunkIndex> - <flaggedWords> - <FlaggedWord> <word>rou</word> <type>UnknownWord</type> <offset>3</offset> </FlaggedWord> </flaggedWords> </SpellingErrors> </spellingErrors> - <spellingSuggestions> - <SpellingSuggestions> <word>rou</word> - <sug> <string>roue</string> <string>rout</string> <string>roux</string> <string>roe</string> <string>row</string> <string>rob</string> </sug> </SpellingSuggestions> </spellingSuggestions> </SpellCheckResult> </SpellCheckResponse> </soap:Body> </soap:Envelope>
In the SOAP response, note that the corrector—in the first string (chunkIndex=0)—has identified an unknown word (FlaggedWord-word=rou), that probably has an error in the third character (offset=3). The suggestions section indicates that the unidentified word has six possible corrections in the dictionary. The second string is not found in the response, signifying it is accepted by the corrector.
The remaining code implementation is elemental and can be used in each SharePoint component (WebParts, WebControls, Web pages, and so forth). The last task is to extract the relevant information from the XML response and present it to the user in the desired way.