2012-03-13 33 views
2

你能幫助我,我怎麼能忽略每個元素xmlns="http://tempuri.org/"聲明在我的輸出asp.net web服務(ASMX)?如何忽略的xmlns =「http://tempuri.org/」從Web服務輸出

<?xml version="1.0" encoding="utf-16"?> 
<ArrayOfData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <DataItem> 
    <Id xmlns="http://tempuri.org/">463d931f-5f14-447d-99cd-289cae2a5b6d</Id> 
    <Created xmlns="http://tempuri.org/">2012-03-13T13:47:13.8626511+01:00</Created> 
    ... 
    </DataItem> 
    ... 

web服務定義如下:

[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
[System.ComponentModel.ToolboxItem(false)]  
public class DataWebService : System.Web.Services.WebService 
{ 

    [WebMethod] 
    public DataCollection GetData() 
    { 
     ... 
    } 
} 

數據項是一個EF實體:

[EdmEntityTypeAttribute(NamespaceName="DataEntityModel", Name="DataItem")] 
[Serializable()] 
[DataContractAttribute(IsReference=true)] 
public partial class DataItem : EntityObject 
{ 

    [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)] 
    [DataMemberAttribute()] 
    public global::System.Guid Id 
    { 
     ... 
    } 
} 


public class DataItemCollection : Collection<DataItem> 
{ 

} 

當我除去[WebService(Namespace = "http://tempuri.org/")]從屬性,其結果是一樣的。

+0

什麼是您的DataItem的樣子? – 2012-03-13 13:26:10

+0

我已經更新的問題 – zosim 2012-03-13 13:32:40

回答

2

不要取下[WebService(Namespace = "http://tempuri.org/")]。相反,使用你自己的命名空間。可能類似http://webservices.yourcompany.com/datawebservice。你也可以在你的實體上放置顯式的命名空間。

不過,我也建議你停止使用ASMX服務,而使用WCF。

+0

我不刪除的命名空間(這只是一個嘗試)。無論是否使用名稱空間,結果都是一樣的。可能當我刪除名稱空間時,序列化程序會改爲使用默認名稱空間。我使用ASMX,因爲我需要它(它在SSIS使用與WCF它不能正常工作)。實體上的顯式命名空間並不能幫助我。 – zosim 2012-03-14 10:18:38

+0

您應該使用'basicHttpBinding'嘗試WCF。看起來與網絡上的ASMX一樣,但它是一種現代技術,而不是像ASMX這樣的傳統技術。 – 2012-03-14 10:45:02

+0

是的,你是對的。這是我的第一個解決方案,但在這種情況下(使用SSIS Web服務任務中的basichttpbinding調用WCF服務)我已經結束了這裏描述的錯誤:http://social.msdn.microsoft.com/Forums/da-DK/adodotnetentityframework/thread/81daac4c-231a-4460-8951-f168adee7d6e。我沒有解決這個錯誤,所以我已經轉移到asmx解決方案。 – zosim 2012-03-14 13:20:17