WCF 服务休息呼叫

发布于 2024-12-19 11:32:56 字数 4586 浏览 0 评论 0原文

我有一个可在 SOAP 和 REST 中调用的 WCF 服务。 如果进行 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;

                }
            }
        }


    }

}

请帮助我!

I have a WCF Service callable in SOAP and REST.
If a make SOAP call this works properly, but with REST I have problems.

In summary, the method return POCO ENTITY, but when I call I get a connection error canceled.
The same thing not happens if I call another method that returns a boolean or a string (ie native types).

The error seemed to me that POCO entity that I'm using was not really (that's what I'm using Devart so pretty sure it is).
So what I did, I created a custom map of it (with same property) and i have used AutoMapper to do mapping.

The problem is still there :-(

This is the .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;
    }

result contains properly my list of objects.

This is 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);

Work properly with this method and operation contract

    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);

this is 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;

                }
            }
        }


    }

}

Please help me!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幸福不弃 2024-12-26 11:32:56

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

来自 MSDN:

使用 IsReference 属性指示 DataContractSerializer
插入保留对象引用信息的 XML 结构。

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

无论如何你在这里不需要它,我没有看到任何循环依赖。

You can't use "IsReference = true" on your DataContract.

From MSDN :

Use the IsReference property to instruct the DataContractSerializer to
insert XML constructs that preserve object reference information.

You are returning JSON, not XML...

Anyways you don't need it here, I don't see any circular dependency.

稀香 2024-12-26 11:32:56

进行 REST 调用时返回的错误代码是什么?还可以尝试在您的服务上启用跟踪,以了解请求通过 REST 失败的原因。要启用跟踪,请点击此链接

尝试使用 fiddler 检查对您的服务发出的请求。

What is the error code you get back when you make the REST call. Also try to enable tracing on your service to see why the request fails via REST. To enable tracing follow this link

Also try to use fiddler to inspect your request that is being made to your service.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文