簡體   English   中英

WCF服務休息電話

[英]WCF Services Rest Call

我有一個可以在SOAP和REST中調用的WCF服務。 如果進行make SOAP調用可以正常工作,但是使用REST時我會遇到問題。

總而言之,該方法返回POCO ENTITY,但是當我調用時,我得到了一個連接錯誤的取消。 如果我調用另一個返回布爾值或字符串(即本機類型)的方法,則不會發生相同的事情。

在我看來,該錯誤似乎並不是我正在使用的POCO實體(這就是我正在使用Devart的東西,因此可以肯定的是)。 所以我做了什么,我創建了一個自定義映射(具有相同的屬性),並且使用了AutoMapper進行映射。

問題仍然存在:-(

這是.svc.cs

 public List<GetLuoghiSimiliByAddressesDTO> GetLuoghiSimiliByAddress(string toponimo, string nomestrada, string civico, int idcomune)
    {
        Agile.SL.Services.IAnagraficaService srv = new Agile.SL.Services.Impl.AnagraficaService();
        List<GetLuoghiSimiliByAddressesDTO> result = new List<GetLuoghiSimiliByAddressesDTO>();
        Mapper.CreateMap<DTOGetLuoghiSimiliByAddress, GetLuoghiSimiliByAddressesDTO>();
        foreach (var dto in srv.GetLuoghiSimiliByAddress(toponimo, nomestrada, civico, idcomune).ToList<DTOGetLuoghiSimiliByAddress>())
        {
            GetLuoghiSimiliByAddressesDTO newdto = Mapper.Map<DTOGetLuoghiSimiliByAddress, GetLuoghiSimiliByAddressesDTO>(dto);
            result.Add(newdto);
        }

        return result;
    }

結果正確包含了我的對象列表。

這是svc

[OperationContract]
    [WebGet(UriTemplate = "GetLuoghiSimiliByAddress?Toponimo={toponimo}&Nome_Strada={nomestrada}&Civico={civico}&Id_Comune={idcomune}",
        BodyStyle = WebMessageBodyStyle.WrappedRequest,
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json)]
    List<GetLuoghiSimiliByAddressesDTO> GetLuoghiSimiliByAddress(string toponimo, string nomestrada, string civico, int idcomune);

使用此方法和操作合同可正常工作

    public bool IsUserAlreadyRegistered(string email)
    {
        Agile.SL.Services.IAnagraficaService srv = new Agile.SL.Services.Impl.AnagraficaService();
        return srv.CheckEmailExistance(email);
    }            

[OperationContract]
[WebGet(UriTemplate = "IsUserAlreadyRegistered?Email={email}",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
bool IsUserAlreadyRegistered(string email);

這是GetLuoghiSimiliByAddressesDTO

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

namespace Merqurio.Agile.DL.Model.Entities
{
    [DataContract(IsReference = true)]
    [Serializable]
    public class GetLuoghiSimiliByAddressesDTO
    {

        private int _Id_Luogo;
        private string _Toponimo;
        private string _Nome_Strada;
        private string _Civico;


        public GetLuoghiSimiliByAddressesDTO()
        {

        }


    /// <summary>
    /// There are no comments for Id_Luogo in the schema.
    /// </summary>
        [DataMember(Order=1)]
        public int Id_Luogo
        {
            get
            {
                return this._Id_Luogo;
            }
            set
            {
                if (this._Id_Luogo != value)
                {
                    this._Id_Luogo = value;
                }
            }
        }


    /// <summary>
    /// There are no comments for Toponimo in the schema.
    /// </summary>
        [DataMember(Order=2)]
        public string Toponimo
        {
            get
            {
                return this._Toponimo;
            }
            set
            {
                if (this._Toponimo != value)
                {
                    this._Toponimo = value;
                }
            }
        }


    /// <summary>
    /// There are no comments for Nome_Strada in the schema.
    /// </summary>
        [DataMember(Order=3)]
        public string Nome_Strada
        {
            get
            {
                return this._Nome_Strada;
            }
            set
            {
                if (this._Nome_Strada != value)
                {

                    this._Nome_Strada = value;

                }
            }
        }


    /// <summary>
    /// There are no comments for Civico in the schema.
    /// </summary>
        [DataMember(Order=4)]
        public string Civico
        {
            get
            {
                return this._Civico;
            }
            set
            {
                if (this._Civico != value)
                {

                    this._Civico = value;

                }
            }
        }


    }

}

請幫我!

您不能在DataContract上使用“ IsReference = true”。

從MSDN:

使用IsReference屬性指示DataContractSerializer插入保留對象引用信息的XML構造。

您正在返回JSON,而不是XML ...

無論如何,您在這里不需要它,我看不到任何循環依賴。

進行REST調用時返回的錯誤代碼是什么? 此外,請嘗試對您的服務啟用跟蹤,以查看為什么請求通過REST失敗。 要啟用跟蹤,請點擊此鏈接

另外,請嘗試使用提琴手檢查對服務提出的要求。

暫無
暫無

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

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