0

I have a WCF service hosted over HTTP. The service has an opertation as the following:

[OperationContract]
MyResponse ProcessRequest(MyRequest request);

and the message contracts:

[MessageContract]
public class MyRequest
{
    [MessageBodyMember(Namespace = "http://company.com/schema/myobjectschema/2", Name = "RequestPayLoad")]
    public RequestPayLoadType RequestPayLoad{ get; set; }
} 

The RequestPayLoadType object is generated out of the schema file using xsd.exe and has all the appropriate namespaces.

Now when I invoke this service operation from SOAP UI, I'm finding that the soap UI request for ProcessRequest operation has all private fields in RequestPayLoadType present in the request. This is actually not accordance with the schema and the java client which is consuming this is breaking because of this.

For example my requestpayloadtype is structured as follows:

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://company.com/schema/myobjectschema/2")]
[System.Xml.Serialization.XmlRootAttribute("EventHeader", Namespace = "http://company.com/schema/myobjectschema/2",
    IsNullable = false)]
public class RequestPayLoadType 
{
    private string messageIDField;
    public string MessageID
    {
        get
        {
            return this.messageIDField;
        }
        set
        {
            this.messageIDField = value;
        }
    }
}

When I send a request to the service the request is forming like this:

 <ns:TimeSeriesPayload>
       <messageIDField >?</messageIDField >
 </ns:TimeSeriesPayload>

My question is: why is the private field apperaing in the request. Why not the public properties. Is there an attribute which I set for preventing this from happening? My schema has deep level nesting so can I use an attrbute on the root level to prevent this from happening?

4

2 に答える 2

0

MessageContract属性を使用する代わりに、意図的に属性を使用していると思いDataContractます。

私の仮定が正しい場合は、内部クラスを関連するMessageBodyMember属性でマークする必要があります。MessageContract内部データ クラスは、およびMessageBody属性でマークされていません。したがって、フレームワークは、内部クラスのすべてのプロパティを公開しようとしていると想定しています。

于 2012-08-14T11:34:33.463 に答える
0

WCF の場合、通常はパラメーター オブジェクトをData Contractとして定義します。あなたRequestPayLoadType[DataContract]属性で定義され、パブリックプロパティMessageIDは属性で定義され[DataMember]ます。これにより、シリアライザーがパブリック プロパティを使用するようになる可能性があります。

于 2012-08-14T11:32:20.257 に答える