Object properties set to null when send objects to wcf service from windows mobile 6 application

StackOverflow https://stackoverflow.com/questions/20273874

  •  06-08-2022
  •  | 
  •  

Question

I have created a WCF Service and hosted it on IIS, I successfully called the service from a windows Mobile 6.0 application, and could easily retrieve data from the service.

The problem is that when I'm trying to post data to the service I found that the properties of the class object sent to the service are all null.

Another issue, when I create the service proxy I found that all generic parameters (ex List<Customer>) are converted to arrays (ex Customer[]).

Here is a sample of my code at the service:

[ServiceContract]
public interface ITest
{
   [OperationContract]
   long AddBoxTransaction(BOXTRANSACTION boxTransaction);
}

Here is a sample of code at the client:

BOXTRANSACTION boxTransaction = new BOXTRANSACTION();
{
    boxTransaction.BOXID = long.Parse(dr["BoxId"].ToString());
    boxTransaction.TRANSACTIONDATE = DateTime.Parse(dr["TransactionDate"].ToString());
    boxTransaction.STATUSID = long.Parse(dr["StatusId"].ToString());

    if(!(dr["CollectorUserId"] is System.DBNull)) 
       boxTransaction.COLLECTORUSERID = int.Parse(dr["CollectorUserId"].ToString());

    boxTransaction.CURRENTLOCATIONID = int.Parse(dr["CurrentLocationId"].ToString());

    if (!(dr["ShelfNumber"] is System.DBNull)) 
       boxTransaction.SHELFNUMBER = int.Parse(dr["ShelfNumber"].ToString());

    if (!(dr["CabinetNumber"] is System.DBNull)) 
       boxTransaction.CABINETNUMBER = int.Parse(dr["CabinetNumber"].ToString());

    //boxTransaction.NUMBEROFDOCUMENTS = int.Parse(dr["NumberOfDocuments"].ToString());
};

long x;
bool y;
LPPFAObj.AddBoxTransaction(boxTransaction,out x, out y); 

Here is the config file:

<services>
  <service name="TestService.Test" behaviorConfiguration="svcBeh">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:81/ITest"/>
      </baseAddresses>
    </host>
    <endpoint address="" binding="basicHttpBinding" contract="TestService.ITest"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="svcBeh">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
Was it helpful?

Solution 2

I found the solution. I have to set the below properties to true in order to pass it to the service:

BOXTRANSACTION boxTransaction = new BOXTRANSACTION();
{
   boxTransaction.BOXID = long.Parse(dr["BoxId"].ToString());
   boxTransaction.BOXIDSpecified = true;
   boxTransaction.TRANSACTIONDATE = DateTime.Parse(dr["TransactionDate"].ToString());
   boxTransaction.TRANSACTIONDATESpecified = true;

   [...]

OTHER TIPS

Your class objects need data annotations for the class itself and all members that you want to be transfered.

Example:

[DataContract]
public class Data
{
  [DataMember]
  public string Member { get; set; }
}

As for your Lists and Arrays, you can set that feature in the wizard that is generating the proxy client. WCF will only transmit collections and it's up to you to decide if you want them represented as arrays or a kind of list in C#.

Your contract does not say anything about out parameters named x and y, where do they come from?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top