服务方法被调用两次 [英] Service method called twice

查看:73
本文介绍了服务方法被调用两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 wcf 创建了一个休息服务.我正在服务方法中编写实体框架代码以从数据库中获取数据.

I have created a rest service using wcf. I am writing Entity framework code within a service method to fetch data from database.

来自浏览器的每次调用都会两次或三次点击服务方法.我在方法中没有发现异常.我之前遇到过同样的问题并解决了它向所有模型添加 DataContract 属性(现在没有帮助).

Every call from browser is hitting the service method twice or thrice. I found no exception within the method. I encountered same problem before and solved it adding DataContract attribute to all the models(not helping now).

可能的原因是什么?请帮忙.

What may be the possible reasons? Please help.

问候艾许

推荐答案

跟踪 Web 服务是起点.

Tracing the web service is the point to start from.

1.- 将以下内容添加到 WCF 项目中的 web.config:

1.- Add the following to the web.config in your WCF project:

<system.diagnostics>
<trace autoflush="true">
</trace>
<sources>
    <source name="System.ServiceModel"
            switchValue="Information, ActivityTracing"
            propagateActivity="true">
        <listeners>
            <add name="sdt"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="WcfDetailTrace.e2e" />
        </listeners>
    </source>
</sources>

然后执行您的服务并检查项目文件夹中的WcfDetaiTrace.e2e"文件的内容,它是一个 XML 文件.这样你就可以很容易地发现你的服务有什么问题.主要问题与:

Then execute your service and checkout the contents of the file "WcfDetaiTrace.e2e" inside the project folder, it's an XML file. That way you will find easily what's wrong with your service. The main problems are related to:

  1. 缺少数据合同/已知类型
  2. DateTime 序列化异常(溢出)
  3. 使用错误的动词访问 REST 条目(GET 但应该是 POST、PUT 或 DELETE)

希望有帮助.

这篇关于服务方法被调用两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆