0

I'm new to working with WCF and i'm struggling to understand whats happening.

I'm trying to retrieve data from my service, which in turn grabs it from the database. To simplify things I wanted to return an object containing the data so that it could just be used immediatly within the UWP app. However, I'm running into the following error when I try to consume the service:

Cannot implicitly convert type 'MBCMobile.ServiceReference1.TaskBreakdown_GetDataResponse' to 'MBCMobile.ServiceReference1.JobTestObject'

The following code is what I'm using:

[ServiceContract]
    public interface IService1
    {
        [OperationContract]
        JobTestObject TaskBreakdown_GetData(int task, int appliance, int job);
    }


[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class Service1 : IService1
{
    public JobTestObject TaskBreakdown_GetData(int task, int appliance, int job)
    {
        JobTestObject jobData = data.TaskBreakdown_GetData(task, appliance, job); //object returned from sql query

        return jobData;
    }
}

To consume my service im using the following:

 private async void GetString()
 {
     ServiceReference1.Service1Client service = new ServiceReference1.Service1Client();
     JobTestObject datalist = await service.TaskBreakdown_GetDataAsync(6153, 18876, 18111);
 }

JobTestObject has the same format in both the service and the UWP app. The service version literally exists as a collection of get/set methods and nothing else. The app version has additional methods, but the exact same get/set methods. I've tried using ServiceReference1.JobTestObject instead to see if that helps but to no avail. I expect that it might be a little naive of me to think an object can be passed to the client this way.

I also tried just returning a list of strings and got a similar error.

I've managed fine in the past with retrieving single values from the service, but now that I want to get multiple values at once I can't understand what I'm doing wrong. Sadly most of the solutions I've found don't relate to UWP apps

Update: As requested

[DataContract]
public class JobTestObject
{
    int appliance_id, manu_id, model_id, landlord_app, applianceType_id, 

    [DataMember]
    public int ApplianceType { get { return applianceType_id; } set { applianceType_id = value; } }
    [DataMember]
    public int Appliance_ID { get { return appliance_id; } set { appliance_id = value; } }
    [DataMember]
    public int ApplianceManufacturer { get { return manu_id; } set { manu_id = value; } }
    [DataMember]
    public int ApplianceModel { get { return model_id; } set { model_id = value; } }
}
Takarii
  • 1,612
  • 2
  • 18
  • 29
  • What does the DataContract look like? – Xeun Aug 08 '16 at 09:32
  • @Xeun see edit. As im new to using WCF, i havent even touched this area yet (which might explain the problem) – Takarii Aug 08 '16 at 09:36
  • Your JobTestObject is transferred via wcf, therefore it should be annotated with the DataContract Attribute, so the serializer knows what to do with those objects. Your update only shows the CompositeTyoe class, which is not used within the wcf service. I Higly suggest you read a bit more about wcf. – Xeun Aug 08 '16 at 09:43
  • @Xeun so if im understanding correctly, I need to rewrite the class at the WCF end to incorporate the datacontract pieces? – Takarii Aug 08 '16 at 09:45
  • @Xeun Please see update, now featuring what i hope you expected to see before (note, ive truncated the class as its quite large) – Takarii Aug 08 '16 at 09:56
  • Yes the datacontract, defines the objects which are trasnferred via wcf. The Servicecontract defines which operatios(operationcontract) are available for a client. See: https://msdn.microsoft.com/en-gb/library/system.runtime.serialization.datamemberattribute(v=vs.110).aspx – Xeun Aug 08 '16 at 10:10
  • @Xeun I've updated my code so that the datamembers are there, as is the contract. I can access the retrieved object using winforms, but have to use `Service.Objectname` to be able to do it. UWP still wont access it though, i expect due to the async nature of the call? – Takarii Aug 08 '16 at 10:36
  • We should not extend this discussion, however. I don't quite get what you mean by: Service.ObjectName. I am not versatile in UWP, but it should work as in every project type. Async call should not be the problem as well. If you are able to request and retrieve data via winforms, you should look further into uwp and wcf communication. You are probably doing something wrong, somewhere. You could also have a look at wcf tracing, which might provide you with some more information: http://stackoverflow.com/questions/4271517/how-to-turn-on-wcf-tracing – Xeun Aug 08 '16 at 10:46

0 Answers0