【问题标题】:Change Prefix To DataContract Inherited From OperationContract Namespaces将前缀更改为继承自 OperationContract 命名空间的 DataContract
【发布时间】:2019-04-25 15:32:19
【问题描述】:

我需要从这个 XML 更改 FORMULARIO 的前缀(Tem: TO Men1:):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:men="http://Mensajes.General.inHeader" xmlns:tem="http://tempuri.org/" xmlns:men1="http://Mensajes.Formularios.Guardar">
   <soapenv:Header>
      <men:inHeader>
         <DSUSUARIO></DSUSUARIO>
         <PWDUSUARIO></PWDUSUARIO>
      </men:inHeader>
   </soapenv:Header>
   <soapenv:Body>
      <tem:Guardar> <!--OperationContract-->
         <tem:FORMULARIO> <!--DataContract-->
         </tem:FORMULARIO>
      </tem:Guardar>
   </soapenv:Body>
</soapenv:Envelope>

问题是我无法将命名空间设置为 OperationContract 以覆盖命名空间基础。在这个追逐中,OperationContract 是 Xml 中 DataContract 的父级。

我的代码是:

[ServiceContract(Namespace = "http://tempuri.org/")]
public interface IComportamiento
{
[OperationContract]
[XmlSerializerFormat]
Resultado Guardar(FORMULARIO FORMULARIO);
}

public class Implementacion : IComportamiento
{
public Resultado Guardar(FORMULARIO FORMULARIO)
{
...
}
}

[DataContract]
public class FORMULARIO
{
}

【问题讨论】:

    标签: xml wcf soap namespaces operationcontract


    【解决方案1】:

    MessageContract 可以更改 Root 元素的命名空间,但它会删除 operationcontract 的元素,并且返回类型也应该更改为 FORMULARIO。

    [ServiceContract(Namespace = "http://tempuri.org/")]
    
    public interface IComportamiento
    {
        [OperationContract]
    
        FORMULARIO Guardar(FORMULARIO FORMULARIO);
    }
    
    [MessageContract(IsWrapped = true, WrapperName = "FORMULARIO", WrapperNamespace = "http://Mensajes.Formularios.Guardar")]
    public class FORMULARIO
    {
    
    }
    

    结果。

    【讨论】:

    • 感谢您的回复,好的,我按照您告诉我的做了,但由于客户需要,我无法更改结构,所以我创建了一个带有 Namespace="tempuri.org" 和 IsWrapped= 的类 Guardar "True" 属性,FORMULARIO 作为 Property,然后通过 OperationContract 作为 Param 传递 Guardar 类。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多