我正在尝试在基于最终用户规范 XML 的本地计算机上创建 WSDL,
使用 C# 和 WCF 我可以创建 WSDL XML。
但是 DataContract 上有一个不同的命名空间,我想删除 DataContract 上的命名空间而不是在 ServiceContract 上删除它。
服务合同代码:
[ServiceContract(Namespace = "mws")]
[XmlSerializerFormat]
public interface IServices
{
[OperationContract]
string TBRequest(Header_BeginCommit Header, Data_Begin Data);
}
服务行为代码:
public class Services : IServices
{
public string TBRequest(Header_BeginCommit Header, Data_Begin Data)
{
return "Ok Guys";
}
public string TCRequest(Header_BeginCommit Header, Data_Commit Data)
{
return "Ok Guys";
}
}
[DataContract(Name = "Header", Namespace = "")]
public class Header_BeginCommit
{
#region Variable
private string m_strUid;
private string m_strRequestor;
private string m_strHost;
private DateTime m_dtProcessDate;
private string m_strGuid;
#endregion
#region Properties
[DataMember(IsRequired = true)]
public string uid
{
get { return m_strUid; }
set { m_strUid = value; }
}
[DataMember(IsRequired = true)]
public string requestorID
{
get { return m_strRequestor; }
set { m_strRequestor = value; }
}
[DataMember(IsRequired = true)]
public string host
{
get { return m_strHost; }
set { m_strHost = value; }
}
[DataMember(IsRequired = true)]
public DateTime date
{
get { return m_dtProcessDate; }
set { m_dtProcessDate = value; }
}
[DataMember(IsRequired = true)]
public string txtID
{
get { return m_strGuid; }
set { m_strGuid = value; }
}
#endregion
}
[DataContract(Name = "Data", Namespace = "")]
public class Data_Begin
{
private double m_dblTimeOut;
[DataMember(IsRequired = true)]
public double timeOut
{
get { return m_dblTimeOut; }
set { m_dblTimeOut = value; }
}
}
从 SOAP UI 测试以检查 XML 结果(您在标题和数据上看到命名空间):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mws="mws">
<soapenv:Header/>
<soapenv:Body>
<mws:TBRequest>
<!--Optional:-->
<mws:Header>
<!--Optional:-->
<mws:uid>?</mws:uid>
<!--Optional:-->
<mws:requestorID>?</mws:requestorID>
<!--Optional:-->
<mws:host>?</mws:host>
<mws:date>?</mws:date>
<!--Optional:-->
<mws:txtID>?</mws:txtID>
</mws:Header>
<!--Optional:-->
<mws:Data>
<mws:timeOut>?</mws:timeOut>
</mws:Data>
</mws:TBRequest>
</soapenv:Body>
</soapenv:Envelope>
如何从 Header 和 Data 中删除名称空间 wms,使其看起来像这样?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mws="mws">
<soapenv:Header/>
<soapenv:Body>
<mws:TBRequest>
<Header>
<uid>?<uid>
<requestorID>?<requestorID>
<host>?<host>
<date>?<date>
<txtID>?<txtID>
</Header>
<Data>
<timeOut>?<timeOut>
</Data>
</mws:TBRequest>
</soapenv:Body>
</soapenv:Envelope>