簡體   English   中英

哪個服務可以允許我將 Xamarin Forms 的多個(復雜類型)參數從服務傳遞給客戶端?

[英]Which Service can allow me to pass Multiple(ComplexType) Parameters from Service to Client For Xamarin Forms?

我知道這是一個老話題,但我閱讀了所有頁面和 forms 並且我幾天來一直在努力解決我的問題。 我正在使用 C#-Xamarin 平台來創建移動應用程序。 我需要將多個參數從服務傳遞給客戶端。 我試過 WCF Resftul 但據我所知 Resftul 只允許傳遞字符串類型,因為它基於 URL。 因此,我無法使用 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." ,我找到了 2 個解決方案,其中一個是https://forums.xamarin.com/discussion/15148/how-to-access-wcf-service-in-ios-platform-using-xamarin和第二個是Monotouch/WCF:如何在沒有 svcutil 的情況下使用 wcf 服務,但隨后我收到有關 CreateChannel() 的錯誤。 有沒有辦法解決 WCF 或 Rest 中的問題? 如果沒有,是否有任何服務允許我將多個參數從服務傳遞給客戶端,尤其是 xamarin.ios?

我的復雜類型 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();
        }
    }

    
}

我的 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));
    }
}

我的界面(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);
}

最后我得到了解決方案。! 我取消了我的 WCF 服務,因為它有一些限制,而且在 iOS 上也不能很好地工作。 由於https://stackoverflow.com/a/20226220/1244848解決方案,我回到了 Web ApI。 它起作用了。現在我可以輕松地傳遞復雜和多類型的參數。 順便說一下,將參數從客戶端傳遞到服務,您需要使用 PostAsync,如果您對使用它感到困惑,您可以查看此https://carldesouza.com/httpclient-getasync-postasync-sendasync-c/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM