Geeks With Blogs
Edmund Zhao's BizTalk abc We share, We learn

I got a problem yesterday when I added a web reference to my BizTalk project. The error didn’t come right away after I added the web reference. Instead, when I tried to open the Reference.xsd or rebuild the project, I got the error “The ‘’ element is not declared…”. I found the reason was because the web service returned a complex type object which contained a DataSet. According to Considerations When Consuming Web Services  DataSet should be supported. If I have a web service return a DataSet as result, there should be no problem because Reference.xsd won’t be created anyway. But this time the returned result was a serializable class, but this class contained a DataSet as a property. Therefore, BizTalk would still try to generate a Reference.xsd file, but inside of the XSD file, the DataSet portion was not handled.


Now I have few options to work around this problem. But first of all I will have to accept this returning class which contains the DataSet and a long list of other simple types propertities, because the class will be automatically generated by a screen scraping software called “FARABI”, and every time I modify the screen scraping navigation, the class will be regenerated again. Since apparently manually change the XSD is not a preferred way to handle this kind of issue, I modified my project following the steps,


  1. Create a wrapper class for the automatically generated the class by FARABI. The new class will have same amount of properties as the FARABI class, they are all simple types, and each one maps to a property in the FARABI class.
  2. Put the following method into Web Service project

            private string ConvertDataSetToString(DataSet ds)


                  byte[] arr;

                  MemoryStream stream = new MemoryStream();

                  XmlSerializer serializer = new XmlSerializer(typeof DataSet));               

                  StreamWriter writer = new StreamWriter(stream, Encoding.Unicode);

                  serializer.Serialize(writer, ds);

                  StreamReader reader = new StreamReader(stream);

                  arr = stream.ToArray();

                  UnicodeEncoding utf = new UnicodeEncoding();


                  return utf.GetString(arr);


  1. Modify the web method. Create an instance of the wrapper class and assign all values of FARABI class properties to their corresponding properties in the new wrapper class instance, use the ConvertDataSetToString method to convert the DataSet in FARABI class to a string in wrapper class, and return the new wrapper class instance.
  2. Add a web reference to BizTalk project using the new web service, and Reference.xsd is created without error. Now I can apply any mapping to the new schema! When I get the string of the original DataSet, I can still write some code to convert it back to a DataSet.   

...Edmund Zhao

Posted on Wednesday, November 30, 2005 6:35 PM | Back to top

Comments on this post: ‘’ element is not declared… error when add a web reference to BizTalk project

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Edmund Zhao | Powered by: