0

I know this is kind of old topic but I read all pages and forms and I've been struggling to solve my problem for days. I'm using C#-Xamarin platforms to create a mobile app. I need to pass multiple parameters from service to client. I tried WCF Resftul but As far as I know Resftul only allows to pass string type because it's based URL. Therefore I couldn't pass my multiple(complex type) parameters with Restful. And then I tried only WCF, I successed for Android, My android side works perfectly but on iOS side I got error which is "MonoTouch does not support dynamic proxy code generation. Override this method or its caller to return specific client proxy instance." , I found 2 solution for it, one of them is https://forums.xamarin.com/discussion/15148/how-to-access-wcf-service-in-ios-platform-using-xamarin ,and the second one is Monotouch/WCF: How to consume the wcf service without svcutil but then I got error about CreateChannel(). Is there any way to solve that problem in WCF or Rest? if no, Is there any service which allows me to pass multiple parameters from service to client, especially xamarin.ios?

My complexType class :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Com.BS.AccrumentAndCollectionDefinition
{
    [DataContract]
    public class ConcreteCollectionDetailQueryCriteria
    {
        
        private long payDeskOid;
        [DataMember(IsRequired = true)]
        public long PayDeskOid
        {
            get { return payDeskOid; }
            set { payDeskOid = value; }
        }

        private DateTime collectionDateStart;
        [DataMember(IsRequired = true)]
        public DateTime CollectionDateStart
        {
            get { return collectionDateStart; }
            set { collectionDateStart = value; }
        }

        private DateTime collectionDateFinish;
        [DataMember(IsRequired = true)]
        public DateTime CollectionDateFinish
        {
            get { return collectionDateFinish; }
            set { collectionDateFinish = value; }
        }

        private string receiptSerial;
        [DataMember(IsRequired = true)]
        public string ReceiptSerial
        {
            get { return receiptSerial; }
            set { receiptSerial = value; }
        }

        private long? receiptNoStart;
        [DataMember(IsRequired = true)]
        public long? ReceiptNoStart
        {
            get { return receiptNoStart; }
            set { receiptNoStart = value; }
        }

        private long? receiptNoFinish;
        [DataMember(IsRequired = true)]
        public long? ReceiptNoFinish
        {
            get { return receiptNoFinish; }
            set { receiptNoFinish = value; }
        }

        private List<string> collectionTypeList;

        [DataMember(IsRequired = true)]
        public List<string> CollectionTypeList
        {
            get { return collectionTypeList; }
            set { collectionTypeList = value; }
        }
        }*/       
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("PayDeskOid:").Append(payDeskOid).Append(Environment.NewLine);
            sb.Append("CollectionDateStart:").Append(collectionDateStart).Append(Environment.NewLine);
            sb.Append("CollectionDateFinish:").Append(collectionDateFinish).Append(Environment.NewLine);
            sb.Append("ReceiptSerial:").Append(receiptSerial).Append(Environment.NewLine);
            sb.Append("ReceiptNoStart:").Append(receiptNoStart).Append(Environment.NewLine);
            sb.Append("ReceiptNoFinish:").Append(receiptNoFinish).Append(Environment.NewLine);
            //sb.Append("CollectionTypeCode:").Append(collectionTypeCode).Append(Environment.NewLine);
            
            return base.ToString();
        }
    }

    
}

My MobileService.cs

public List<ConcretePayDeskBaseCollection> ListPayDeskBasedCollections(string userName, string password, ConcreteCollectionDetailQueryCriteria collectionDetailQueryCriteria)
{
    //ConcreteCollectionDetailQueryCriteria collectionDetailQueryCriteria = new ConcreteCollectionDetailQueryCriteria();
    try
    {
        ReportingOperations reportingOperations = new ReportingOperations();
        return reportingOperations.ListPayDeskBasedCollections(collectionDetailQueryCriteria);
    }
    catch (BSException e)
    {
        FileLogger.Error(CLASS_NAME, "ListPayDeskBasedCollections", e.Message, e.StackTrace, collectionDetailQueryCriteria);
        BSCommunicationException commException = new BSCommunicationException();
        commException.Id = e.Id;
        commException.ExceptionMessage = e.ExceptionMessage;
        throw new FaultException<BSCommunicationException>(commException, new FaultReason(commException.ExceptionMessage));
    }
    catch (Exception e)
    {
        FileLogger.Error(CLASS_NAME, "ListPayDeskBasedCollections", e.Message, e.StackTrace, collectionDetailQueryCriteria);
        BSCommunicationException commException = PrepareCommunicationException(e);
        throw new FaultException<BSCommunicationException>(commException, new FaultReason(commException.ExceptionMessage));
    }
}

And My Interface(IMobileService):

[ServiceContract]
public interface IMobileService
{
    [OperationContract]
    [FaultContract(typeof(BSCommunicationException))]
    [WebInvoke(Method = "POST", UriTemplate = "/ListPayDeskBasedCollections/{userName}/{password}/{collectionDetailQueryCriteria}", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    List<ConcretePayDeskBaseCollection> ListPayDeskBasedCollections(string userName, string password, ConcreteCollectionDetailQueryCriteria collectionDetailQueryCriteria);
}
Veysel Turan
  • 203
  • 2
  • 14
  • The Xamarin platform support for WCF is limited to text-encoded SOAP messages over HTTP/HTTPS using the BasicHttpBinding class. For more information about it, you can refer to this link: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/web-services/wcf – Ding Peng Mar 24 '21 at 08:05
  • Hi Ding Peng, First of all, thank you for your reply, I already read that link many times. I know WCF is limited but Web-Api does not allow me to pass multiple parameters. That's why I'm trying to solve WCF problem. Do you recommend amy other service to pass multi parameters and work suitable xamarin.ios? – Veysel Turan Mar 24 '21 at 08:26
  • it is certainly possible to pass multiple complex parameters via REST. I don't know what gave you the impression that this is not supported. You also specifically say "from service to client" which I think is the opposite of what you actually want. – Jason Mar 24 '21 at 10:31
  • Hi Jason!, Thank you for your respond. I have a Rest service which has some multi type classes. I want to send some paramaters with client and get values from service. When I tried to pass parameters with UriTemplate, I got error kind of "non string". Could you please give a basic example of how to pass multiple complex parameters via REST? – Veysel Turan Mar 24 '21 at 10:44
  • if you want to know what is wrong with your code, you need to post THAT code. – Jason Mar 25 '21 at 01:41
  • Hi Jason!, I edited my post with my codes. I still haven't found any way to post complex-type therefore I'm trying to post it with converting json in a temporary way. And I haven't successed yet. If there is no way to post complex type could you give me an example how to convert my complext type to json and post it with url? – Veysel Turan Mar 25 '21 at 06:13

1 Answers1

0

Finally I got a solution!! I canceled my WCF Service because it has some limitation and also not work well enough with iOS. I came back to Web ApI thanks to https://stackoverflow.com/a/20226220/12448483 .Here the solution for me. It worked!! And now I pass complex and multi type parameters easily. By the way Passing parameters from client to service you need to use PostAsync, if you are confused to use it the you can check this https://carldesouza.com/httpclient-getasync-postasync-sendasync-c/

Veysel Turan
  • 203
  • 2
  • 14