從傳回 ADO.NET 資料集 (System.Data.DataSet) 的 Web 服務建立 InfoPath 表單時,可能會從 InfoPath 收到下列錯誤訊息:
XML 資料檔包含 XML 結構描述資訊不允許的。
InfoPath 無法直接使用 ADO.NET 資料集。InfoPath 會使用一般的 XML 裝載。Web 服務所傳回的 ADO.NET 資料集被序列化為特殊的 XML 格式,直接使用 InfoPath 可防止 ADO.NET 資料集。
- 在定義方法和屬性的 Web 服務之 Web 服務描述語言檔案,DataSet 型別由開放結構描述標記 < xsd: 任何 / >。InfoPath 可以推斷 XML 文件由 Web 服務所傳回的結構描述。不過,InfoPath 必須請呼叫至 Web 服務執行這個範例。
- ADO.NET 資料集包含描述資料,儲存在其中一個內置結構描述。 這個版本的 InfoPath 不支援內置結構描述。
- 在 ADO.NET 資料集中資料包裝在 <diffgr:diffgram> XML 項目,不述內嵌結構描述。 XML 項目包含 ADO.NET 資料集的資料也有不結構描述中所述的其他屬性。 因為資料不符合結構描述,資料無法驗證 InfoPath 表單中。
- InfoPath 不具有類似 ADO.NET 資料集的變更追蹤的內建支援。例如,ADO.NET 資料集追蹤欄位,而接受的已新增、 變更,或刪除,因為變更是最後一個資料列。(這是 diffgram 項目與 diffgr"命名空間,在 XML 資料流的目的)。若要支援變更追蹤,InfoPath 就必須交運.NET Framework 及裝載資料集物件來管理 XML 資料或重新實作功能。但是,這兩這些選項都適用於這個版本的 InfoPath。
解決這個問題的 Microsoft Office InfoPath 2003 Service Pack 1 (SP1)。如果要解決這個問題,取得最新的 Service Pack,Microsoft Office 2003。InfoPath 2003 SP1 完全支援具型別資料集,並可讓您從 InfoPath 2003 中傳回 ADO.NET 資料集的 Web 服務建立表單。
如需詳細資訊按一下 [下面的文件編號,檢視 「 Microsoft 知識庫 」 中的發行項]:
870924
(http://support.microsoft.com/kb/870924/
)
如何取得最新的 Service Pack,Office 2003
如果要解決這個問題,建立一個新的 Web 服務方法可接受從原始的 Web 服務方法傳回的 ADO.NET 資料集。 移除內嵌結構描述、 diffgram] 項目和屬性。 回到 InfoPath 已清除的 XML。 請參閱 < 其他相關資訊 > 一節的這項因應措施的兩個可能的實作。
重現這個問題的步驟
- Microsoft Visual Studio.NET 在建立新的 Microsoft C# ASP.NET Web 服務專案。 將這個專案的名稱變更為 NorthwindDataSet。
您可以只要 http://localhost/NorthwindDataSet 中變更位置。 - 在 [專案] 功能表上按一下 [加入 Web 服務。 命名新的 Web 服務 CustomerInfo.asmx。
- 將下列程式碼加入至新的 CustomerInfo.asmx Web 服務:
/************************************************************************
* GetCustomerInfo -- This method retrieves information from the
* Customer table of the Northwind database and then returns it in an
* ADO.NET DataSet.
* Parameters: CustomerID is the string that contains the CustomerID of the
* customer to retrieve the information for.
* Returns: An ADO.NET DataSet that contains information about the customer.
* *********************************************************************/
[WebMethod]
public System.Data.DataSet GetCustomerInfo( string CustomerID )
{
try
{
//Create a Microsoft SQL Server connection to the local SQL Server.
System.Data.SqlClient.SqlConnection theConnection = new SqlConnection();
theConnection.ConnectionString = "Data Source=(local);" +
"Integrated Security=SSPI;Initial Catalog=northwind";
//Create an SQL Command to query the data.
System.Data.SqlClient.SqlCommand theCommand = new SqlCommand();
theCommand.Connection = theConnection;
theCommand.CommandText = "SELECT \"CustomerID\",\"CompanyName\"," +
"\"ContactName\",\"ContactTitle\",\"Address\",\"City\",\"Region\"," +
"\"PostalCode\",\"Country\",\"Phone\",\"Fax\" FROM \"Customers\" " +
"WHERE CustomerID='" + CustomerID + "'";
//Create an SQL DataAdapter to read the data.
System.Data.SqlClient.SqlDataAdapter theDataAdapter = new SqlDataAdapter();
theDataAdapter.SelectCommand = theCommand;
//Open the command, and then read the data.
theConnection.Open();
System.Data.DataSet theCustomerInfo = new DataSet();
theCustomerInfo.DataSetName = "CustomerInfo";
theCustomerInfo.Namespace = "http://localhost/NorthwindDataSet/CustomerInfo";
theDataAdapter.Fill( theCustomerInfo, "Customers" );
//Clean up.
theConnection.Close();
//Return the result.
return theCustomerInfo;
}
catch(Exception ex)
{
return null;
}
}
範例的程式碼會嘗試連線到 Web 服務為在同一部電腦執行 Microsoft SQL Server 的電腦。 或者,您可以變更 System.Data.SqlConnection 物件會使用它來連線到執行 SQL Server 的不同電腦的連接字串。 您可能必須設定為允許 Web 服務,以存取資料庫的 SQL Server 使用權限。如需詳細資訊按一下 [下面的文件編號,檢視 「 Microsoft 知識庫 」 中的發行項]: 815154
(http://support.microsoft.com/kb/815154/
)
如何: 設定.NET 應用程式的 SQL Server 安全性
- CustomerInfo.asmx.cs 頁面頂端加入下列程式碼 使用 陳述式:
using System.Data.SqlClient;
- 編譯 NorthwindDataSet 專案。
- 啟動 InfoPath。在 [檔案] 功能表上按一下 [設計表單]。
- 在 [設計表單] 工作窗格中,按一下 [新資料來源]。
- 在 [資料來源安裝精靈] 對話方塊選取 [Web 服務] 作為資料來源的類型,然後按一下 [下一步]。
- 選取 [接收資料,然後按一下 [下一步]。
- 輸入要 CustomerInfo Web 服務 (比方說 http://localhost/NorthwindDataSet/CustomerInfo.asmx) URL,然後按一下 [下一步]。
- 選取作業的 GetCustomerInfo 方法,然後按一下 [下一步]。
- 選取 s0:CustomerID] 參數,然後按一下 [設定範例值...]。 在 [設定值] 對話方塊鍵入 ALFKI,再按 [確定]。
- 按一下 [下一步]。
附註InfoPath 會顯示本文 < 徵狀 > 一節中的錯誤訊息。
因應措施
若要處理此類問題,繞過,您可以使用類似下列的步驟來新增 Web 服務方法,可以移除不相容的項目 ADO.NET 資料集的 XML 的步驟。 您可以這樣這樣 XML 資料可以使用 InfoPath。 Web 服務方法可以從 XML 的資料移除內置結構描述資訊,或 Web 服務方法可以序列化強型別包裝函式類別中的 XML 資料並傳回的。
每一種方法各有優缺點。
解決方法 1
移除內嵌結構描述和不相容的 XML 屬性
此解決是很好的因為它是簡單的實作。 此外,如果因為任何原因而變更原始的 Web 服務傳回的 XML 資料,這項因應措施不需要做任何的變更來使用新的資料。
不過,這項因應措施也有缺點。 這項因應措施並不會說明 XML 資料的結構描述。因此,InfoPath 必須推斷結構描述從範例資料。 如果所有可能的項目和 Web 服務方法可以傳回的屬性,並不包含範例資料,InfoPath 會推斷結構描述不會包含這些項目。 如果您在執行查詢以傳回項目或屬性不是位在範例呼叫 InfoPath 會顯示錯誤。
若要實作其他可行方案 1,請依照下列步驟執行:
- 在 Visual 的 Studio.NET 開啟 NorthwindDataSet 專案。
- 在 [專案] 功能表上按一下 [加入 Web 服務。 命名新的 Web 服務 IPCustomerInfo.asmx。
- 將下列程式碼加入至新的 IPCustomerInfo.asmx Web 服務:
/************************************************************************
* GetCustomerInfoNoSchema: This method calls the GetCustomerInfo
* method of the CustomerInfo.asmx Web service, and then strips the
* inline schema from the resulting DataSet.
* Parameters: CustomerID is the string that contains the CustomerID of the
* customer to retrieve information for.
* Returns: An XML Document with no inline schema.
* *********************************************************************/
[WebMethod]
public System.Xml.XmlDocument GetCustomerInfoNoSchema( string CustomerID )
{
//Get the core data.
CustomerInfo theCustomerInfoService = new CustomerInfo();
System.Data.DataSet theDataSet =
theCustomerInfoService.GetCustomerInfo( CustomerID );
//Create a new XmlDocument from the data of the dataset.
System.Xml.XmlDocument theDocument = new System.Xml.XmlDocument();
theDocument.LoadXml( theDataSet.GetXml() );
//Return the result.
return theDocument;
}
的範例程式碼使用原始的 Web 服務來提供 ADO.NET 資料集,然後會建立一個新的 XML 文件不含內置結構描述資訊。 - 編譯 NorthwindDataSet 專案。
- 啟動 InfoPath。在 [檔案] 功能表上按一下 [設計表單]。
- 在 [設計表單] 工作窗格中,按一下 [新資料來源]。
- 在 [資料來源安裝精靈] 對話方塊選取 [Web 服務] 作為資料來源的類型,然後按一下 [下一步]。
- 選取 [接收資料,然後按一下 [下一步]。
- 輸入要 IPCustomerInfo Web 服務 (比方說 http://localhost/NorthwindDataSet/IPCustomerInfo.asmx) URL,然後按一下 [下一步]。
- 選取作業的 GetCustomerInfoNoSchema 方法,然後按一下 [下一步]。
- 選取 s0:CustomerID] 參數,然後按一下 [設定範例值]。 在 [設定值] 對話方塊鍵入 ALFKI,再按 [確定]。
- 按一下 [下一步],然後再按一下 [完成]。
- 將 [客戶編號] 欄位從 queryFields 群組在 [資料來源] 工作窗格中移動,然後將 [客戶編號] 欄位新增到 查詢 檢視。
- 從資料來源] 工作窗格的 [dataFields] 群組移動 [客戶] 群組,然後將 [客戶] 群組新增到 資料輸入 檢視。按一下 [有控制項的區段]。
- 預覽,並測試表單。 請注意有些客戶 ID 如 皇后,查詢遇到錯誤因為範例資料未包含 Web 服務可傳回的所有可能元素。
解決方法 2
建立強型別包裝函式類別,以序列化 XML 資料的 ADO.NET 資料集
這項因應措施會比先前的因應措施實作更困難。 此外,與,搭配使用,且 Web 服務方法必須不變更它會傳回資料的結構描述每個 Web 服務方法必須被配合這項因應措施。 不過,這項因應措施描述 XML 資料,它會傳回結構的描述。因此,InfoPath 沒有推斷的資料結構。 結果從這項因應措施建立 InfoPath 表單並不容易由選擇性的項目和屬性所造成的錯誤。
- 在 Microsoft Internet Explorer 移至 CustomerInfo Web 服務測試網頁 (比方說 http://localhost/NorthwindDataSet/CustomerInfo.asmx) 的 URL。
- 按一下 GetCustomerInfo 移至測試頁面為該方法。
- 在 [客戶編號] 文字方塊中輸入 ALFKI,然後按一下 [叫用]。
- 從所產生的 XML,複製 <xs:schema> 項目和其所有的子系和再貼上它們新的文字 「 記事本 」 中的文件。
- 從貼上的文字移除 - 字元,然後將文件儲存成 CustomerInfo.xsd。
- 開啟 Visual Studio.NET 命令提示字元並移動目錄至您用來儲存 CustomerInfo.xsd。
- 若要從結構描述檔案建立包裝函式類別使用下列程式:
xsd.exe CustomerInfo.xsd /c /l:cs
- 在 Visual 的 Studio.NET 開啟 NorthwindDataSet 專案。
- 在 [專案] 功能表上按一下 [加入現有項目]。
- 移至您建立以 Xsd.exe] 工具的 CustomerInfo.cs 檔案,然後按一下 [開啟]。
- 加入命名空間 CustomerInfoWrapper CustomerInfo 類別和 CustomerInfoCustomers 類別周圍。
- 將下列程式碼加入至 IPCustomerInfo.asmx Web 服務:
/************************************************************************
* GetCustomerInfoWrapper: This method calls the GetCustomerInfo
* method of the CustomerInfo.asmx Web service, and then strips the
* inline schema from the resulting DataSet.
* Parameters: CustomerID is the string that contains the CustomerID of the
* customer to retrieve information for.
* exampleData is the wrapper class to fill with the data from the
* ADO.NET DataSet.
* Returns: none
* *********************************************************************/
[WebMethod]
public void GetCustomerInfoWrapper( string CustomerID,
out CustomerInfoWrapper.CustomerInfo exampleData )
{
//Get the core data.
CustomerInfo theCustomerInfoService = new CustomerInfo();
System.Data.DataSet theDataSet =
theCustomerInfoService.GetCustomerInfo( CustomerID );
theDataSet.Namespace = "http://localhost/NorthwindDataSet/CustomerInfo";
//Create an in-memory stream to write the DataSet to.
System.IO.MemoryStream theStream = new System.IO.MemoryStream();
//Write the DataSet to the stream.
theDataSet.WriteXml( theStream, XmlWriteMode.IgnoreSchema );
//Move the streams seek pointer back to the beginning, or
//deserialization will fail.
theStream.Seek(0, System.IO.SeekOrigin.Begin );
//Create an XML Serializer to read the DataSet.
System.Xml.Serialization.XmlSerializer ser = new
System.Xml.Serialization.XmlSerializer(
typeof(CustomerInfoWrapper.CustomerInfo));
//Deserialize a CustomerInfo wrapper from the stream.
exampleData = ((CustomerInfoWrapper.CustomerInfo)
(ser.Deserialize( theStream )));
return;
}
的範例程式碼使用原始的 Web 服務提供了 ADO.NET 資料集,然後會建立一個新的 XML 文件不含內置結構描述資訊。 - 編譯 NorthwindDataSet 專案。
- 啟動 InfoPath。在 [檔案] 功能表上按一下 [設計表單]。
- 在 [設計表單] 工作窗格中,按一下 [新資料來源...]。
- 在 [資料來源安裝精靈] 對話方塊選取 [Web 服務] 作為資料來源的類型,然後按一下 [下一步]。
- 選取 [接收資料,然後按一下 [下一步]。
- 輸入要 IPCustomerInfo Web 服務 (比方說 http://localhost/NorthwindDataSet/IPCustomerInfo.asmx) URL,然後按一下 [下一步]。
- 作業,選取 GetCustomerInfoWrapper] 方法,然後按一下 [下一步]。
請注意 InfoPath 不會提示您指定的 Web 服務方法的範例值。 - 按一下 [完成]。
- 將 [客戶編號] 欄位從 queryFields 群組在 [資料來源] 工作窗格中移動,然後將 [客戶編號] 欄位新增到查詢檢視。
- 從資料來源] 工作窗格的 [dataFields] 群組移動 [客戶] 群組,然後將 [客戶] 群組新增到 資料輸入 檢視。
- 預覽並測試表單。
請注意,此表單中的任何有效的客戶識別碼運作。
文章編號: 822020 - 上次校閱: 2006年7月28日 - 版次: 2.4
這篇文章中的資訊適用於:
- Microsoft Office InfoPath 2003
| kbmt kbtshoot kbxml kbprb KB822020 KbMtzh |
機器翻譯重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:
822020
(http://support.microsoft.com/kb/822020/en-us/
)
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。