内部复杂类型中的Soap名称空间不正确

时间:2015-02-16 14:34:38

标签: c# wcf soap messagecontract

我正在使用MessageContract。

这里生成了错误的SOAP消息:

<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>

&lt; a :ANotherBool&gt;,&lt; a :AnotherStringValue&gt; - 是不正确的。命名空间必须为“http://my.site/rev2015”。

这是我的代码:

[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)
    {...}
}

怎么做?

0 个答案:

没有答案