0

I have a Core service and a Micro service. The Micro service references the core WCF service. When I add the reference, references.cs contains classes with my private properties exposed as public, and with a field suffix on all my properties

for example:

public string SMCD { get; set; } becomes private string sMCDField;

below are my referenced classes:

CoreInterface.cs

[ServiceContract(Namespace = Constants.Namespace, Name = "M3ApiCalls")]
public interface IService
{

    [System.ServiceModel.XmlSerializerFormatAttribute()]
    [OperationContractAttribute(AsyncPattern = true)]
    IAsyncResult BeginCRS100MI_List(string Salesperson, decimal Timestamp, AsyncCallback asyncCallback, object state);
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    CRS100MI_ListResult EndCRS100MI_List(IAsyncResult result);

    ...(more operations)
}

CRS100MI_ListResult.cs

[Serializable()]
[XmlSerializerFormat()]
[XmlRoot(ElementName = "CRS100MI_List",DataType = "System.Xml.XmlElement",Namespace = "http://companynamespace")]
public class CRS100MI_ListResult
{
    [XmlElement(Order = 0)]
    public string Result = "";

    [XmlElement(Order = 1)]
    public List<string> Messages = new List<string>();

    [XmlElement(Order = 2)]
    public List<M3Message> ResultMessage = new List<M3Message>();

    [XmlElement(Order = 3)]
    public List<CRS100MI_ListRecordResult> Record = new List<CRS100MI_ListRecordResult>();

    public CRS100MI_ListResult Parse(List<Dictionary<string, string>> list)
    {
        //parses a list of dictionaries to CRS100MI_ListRecordResult
    }
}

[Serializable()]
[XmlSerializerFormat()]
[XmlRoot(ElementName = "CRS100MI_ListRecord", DataType = "System.Xml.XmlElement", Namespace = "http://companynamespace")]
public class CRS100MI_ListRecordResult
{


    [XmlElement(Order = 0)]
    public string Result { get; set; }

    [XmlElement(Order = 1)]
    public string ErrorMessage { get; set; }

    [XmlElement(Order = 2)]
    public List<string> Messages { get; set; }

    [XmlElement(Order = 3)]
    public List<M3Message> ResultMessage { get; set; }

    [XmlElement(Order = 4)]
    public string SMCD { get; set; }

    [XmlElement(Order = 5)]
    public string TX40 { get; set; }

    [XmlElement(Order = 6)]
    public string TX15 { get; set; }

    [XmlElement(Order = 7)]
    public string SDEP { get; set; }

    [XmlElement(Order = 8)]
    public string BUAR { get; set; }

    [XmlElement(Order = 9)]
    public string PWMT { get; set; }

    [XmlElement(Order = 10)]
    public string SHOP { get; set; }

    [XmlElement(Order = 11)]
    public string LOSD { get; set; }


}

When I call upon this core wcf service in my micro wcf webservice and I return the result it serializes the auto generated class and gives me

     <getCRS100StuffResult xmlns:a="http://schemas.datacontract.org/2004/07/RA_Tibco.CoreService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:PropertyChanged i:nil="true" xmlns:b="http://schemas.datacontract.org/2004/07/System.ComponentModel"/>
        <a:messagesField i:nil="true" xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:recordField>
           <a:CRS100MI_ListRecordResult>
              <a:PropertyChanged i:nil="true" xmlns:b="http://schemas.datacontract.org/2004/07/System.ComponentModel"/>
              <a:bUARField i:nil="true"/>
              <a:errorMessageField i:nil="true"/>
              <a:lOSDField>0</a:lOSDField>
              <a:messagesField i:nil="true" xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
              <a:pWMTField i:nil="true"/>

after searching for a bit i stumbled on the following StackOverflow question: Why does WCF sometimes add "Field" to end of generated proxy types?

So I made sure to follow the instructions given, but after saving, re-adding the service reference and adding it to SOAPUI it still presents me with this issue. What am I doing wrong?

Dennis Lukas
  • 483
  • 2
  • 6
  • 20
  • You cannot serialize an Interface!!! See : https://social.msdn.microsoft.com/Forums/en-US/bac96f79-82cd-4fef-a748-2a85370a8510/xmlserialization-with-interfaces?forum=asmxandxml – jdweng Apr 02 '19 at 14:28
  • @jdweng am I not declaring the format on the interface? removing `[XmlSerializerFormat()]` from the interface declaration did nothing. – Dennis Lukas Apr 02 '19 at 14:34
  • try the USE property, add the following code to interface.[ServiceContract,XmlSerializerFormat(Use =OperationFormatUse.Encoded)] – Abraham Qian Apr 03 '19 at 03:24
  • @AbrahamQian Thanks for your input, but sadly it didn't help. I also noticed that even though when I add the service reference and choose for collection type to be `System.Collections.Generic.List` , it still auto generates classes where the collections are arrays. – Dennis Lukas Apr 03 '19 at 09:08

1 Answers1

1

Looking carefully through your CRS100MI_ListResult.cs I noticed you do not use DataContract and DataMember attributes.

Use them instead of the [Serializable()] attribute and it should work fine.

Barr J
  • 10,636
  • 1
  • 28
  • 46
  • But is it not required since I am using XmlSerialiser instead of DataContractSerializer? – Dennis Lukas Apr 08 '19 at 10:03
  • 1
    I decided to go your way and changed it so i was using the datacontractserializer, and now i can see it has worked. it still generates the "-field"attributes but as private properties, and the right ones are exposed publicly. – Dennis Lukas Apr 08 '19 at 10:25