C# 如何省略xmlns=";http://tempuri.org/" 从web服务输出

C# 如何省略xmlns=";http://tempuri.org/" 从web服务输出,c#,web-services,xml-serialization,C#,Web Services,Xml Serialization,你能帮我怎么省略xmlns=”吗http://tempuri.org/“从asp.net web服务(asmx)输出的每个元素中的声明?” 数据项是EF实体: [EdmEntityTypeAttribute(NamespaceName="DataEntityModel", Name="DataItem")] [Serializable()] [DataContractAttribute(IsReference=true)] public partial class DataItem : Enti

你能帮我怎么省略
xmlns=”吗http://tempuri.org/“
从asp.net web服务(asmx)输出的每个元素中的声明?”

数据项是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>
{

}
[EdmEntityTypeAttribute(NamespaceName=“DataEntityModel”,Name=“DataItem”)]
[可序列化()]
[DataContractAttribute(IsReference=true)]
公共部分类数据项:EntityObject
{
[EdmScalarPropertyAttribute(EntityKeyProperty=true,IsNullable=false)]
[DataMemberAttribute()]
公共全局::System.Guid Id
{
...
}
}
公共类DataItemCollection:集合
{
}

当我删除
[WebService(名称空间=”http://tempuri.org/”)
从属性中,结果是相同的。

不要删除
[WebService(命名空间=”http://tempuri.org/”)
。相反,使用您自己的名称空间。可能是
http://webservices.yourcompany.com/datawebservice
。您还可以在实体上放置显式名称空间


但是,我也建议您停止使用ASMX服务,改用WCF。

您的数据项是什么样子的?我没有删除名称空间(只是一次尝试)。无论是否使用名称空间,结果都是相同的。当我删除名称空间时,序列化程序可能会改为使用默认名称空间。我之所以使用asmx,是因为我需要它(它在SSI中使用,在wcf中无法正常工作)。实体上的显式名称空间对我没有帮助。您应该使用
basicHttpBinding
尝试WCF。看起来和网络上的ASMX一样,但它是一种现代技术,而不是像ASMX那样的传统技术。是的,你说得对。这是我的第一个解决方案,但在此场景中(使用SSIS Web服务任务中的basichttpbinding调用WCF服务),我以下面描述的错误结束:。我没有解决此错误,因此我已转到asmx解决方案。
[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()
    {
        ...
    }
}   
[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>
{

}