我有一个在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;
}
}
}
}
}
请帮助我!
答案 0 :(得分:0)
您不能在DataContract上使用“IsReference = true”。
来自MSDN:
使用IsReference属性指示DataContractSerializer 插入保留对象引用信息的XML构造。
您正在返回JSON,而不是XML ......
无论如何你不需要它,我没有看到任何循环依赖。
答案 1 :(得分:0)
进行REST调用时,您得到的错误代码是什么?还尝试在您的服务上启用跟踪,以查看请求因REST而失败的原因。要启用跟踪,请遵循此link
还尝试使用fiddler检查您的服务请求。