Incorrect Soap's namespaces in inner complex types

帅比萌擦擦* 提交于 2019-12-12 01:55:30

问题


Im using the MessageContract.

Here the wrong SOAP message, which is generated:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
...
</s:Header>
<s:Body>
<BoolValue xmlns="http://my.site/rev2015">true</BoolValue>
<StringValue xmlns="http://my.site/rev2015">HelloWorld</StringValue>
<InnerType xmlns="http://my.site/rev2015" xmlns:a="http://schemas.datacontract.org/2004/07/Server" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:ANotherBool>true</a:ANotherBool>
<a:AnotherStringValue>AnotherHelloWorld</a:AnotherStringValue>
</InnerType>
</s:Body>
</s:Envelope>

<a:ANotherBool>, <a:AnotherStringValue> - is not correct. Namespace must be "http://my.site/rev2015".

Here the my code:

[ServiceContract(Namespace = "http://my.site/rev2015")]
[ServiceKnownType(typeof(InnerType))]
public interface IService1
{
    [OperationContract]
    CompositeType GetDataUsingDataContract(CompositeType composite);
}

[MessageContract(WrapperNamespace = "http://my.site/rev2015", IsWrapped = false)]
public class CompositeType
{
    [MessageBodyMember(Namespace = "http://my.site/rev2015")]
    public bool BoolValue;
    [MessageBodyMember(Namespace = "http://my.site/rev2015")]
    public string StringValue;
    [MessageBodyMember(Namespace = "http://my.site/rev2015")]
    public InnerType InnerType;
}

[MessageContract(WrapperNamespace = "http://my.site/rev2015", IsWrapped = false)]
public class InnerType
{
    [MessageBodyMember(Namespace = "http://my.site/rev2015")]
    public bool ANotherBool;
    [MessageBodyMember(Namespace = "http://my.site/rev2015")]
    public string AnotherStringValue;
}

// impl
[ServiceBehavior(Namespace = "http://my.site/rev2015")]
public class Service1 : IService1
{
    public CompositeType GetDataUsingDataContract(CompositeType composite)
    {...}
}

How to do that?


回答1:


Must be

[ServiceContract(Namespace = "http://my.site/rev2015")]
[XmlSerializerFormat]
public interface IService1
{
  [OperationContract]
  [XmlSerializerFormat]
  CompositeType GetDataUsingDataContract(CompositeType composite);
}

[MessageContract(WrapperNamespace = "http://my.site/rev2015", IsWrapped = true)]
public class InnerType
{
  [MessageBodyMember(Namespace = "http://my.site/rev2015")]
  public bool ANotherBool;
  [MessageBodyMember(Namespace = "http://my.site/rev2015")]
  public string AnotherStringValue;
}

1.XmlSerializerFormat

2.IsWrapped = true



来源:https://stackoverflow.com/questions/28543732/incorrect-soaps-namespaces-in-inner-complex-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!