WCF data contarct definition

Vara Prasad 1 Reputation point
2022-07-14T00:54:24.517+00:00

I m trying create a wcf interface which should produce payload format as below , please help

<availmessage>
<name>?</name>
<datatype>?</datatype>
<!~~zero or more —!>
<blocks>
<start>?</start>
<end>?</end>
</blocks>
</availmessage>

What I’m getting is

<availmessage>
<name>?</name>
<datatype>?</datatype>
<blocks>
<!———zero or more ———-!>
<blockdatatype>
<start>?</start>
<end>?</end>
</blockadatatye>
</blocks>
</availmessage>

Class definition
[datacontract]
Public class availmessage
{
Public string name { get;set;}
Public string datatype { get; set;}
Public List<blockdatatype> blocks { get; set;}
}

[Datacontract]
Public class blockdatatype
{
Public string start { get; set;}
Public string end { get; set; }
}

.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,100 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,288 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. 64337516 1 Reputation point
    2022-07-14T00:57:10.137+00:00

    <start>?</start>


  2. Lan Huang-MSFT 30,176 Reputation points Microsoft Vendor
    2022-07-14T06:37:09.077+00:00

    Hi @Vara Prasad ,
    I suggest you can use Message Contracts instead, because Message Contracts include IsWrapped property, which can help you achieve what you want.

    [MessageContract(IsWrapped = false)]    
    

    To suppress the wrapper element, set the IsWrapped property to false. To control the name and the namespace of the wrapper element, use the WrapperName and WrapperNamespace properties.

    https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-message-contracts#controlling-whether-the-soap-body-parts-are-wrapped
    https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.messagecontractattribute.iswrapped?view=dotnet-plat-ext-6.0

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.