json - 未找到端点 WCF

标签 json wcf entity-framework c#-4.0

我有我托管的WCF库,登录功能运行良好,但第二个函数ReturnCounter

界面是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ServiceModel;
using System.ServiceModel.Web;

namespace PMAService
{
    [ServiceContract]
    public interface IPMA
    {
        [OperationContract]
        string Login(string username, string password);

        [OperationContract]
        List<usp_ReturnEncounter_Result> ReturnEncounter();



    }
}

代码是

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Web;
using System.Security.Cryptography;
using System.Web.Security;

namespace PMAService
{
    public class PMA : IPMA
    {

        [WebInvoke(Method = "GET",
   ResponseFormat = WebMessageFormat.Json,
   UriTemplate = "LogIn/{username}/{password}")]
        public string Login(string username, string password)
        {
            if (Membership.ValidateUser(username, password))
                return "true";
            else
                return "false";
        }

        // Method to retrieve the Counter 
        [WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "ReturnEncounter")]
        public List<usp_ReturnEncounter_Result> ReturnEncounter()
        {
            using (PMAEntities context = new PMAEntities())
            {
              return   context.usp_ReturnEncounter().ToList();
            }
        }

    }
}

我连接到 Entity Framework 的位置

web.config 看起来像

<?xml version="1.0"?>
<configuration>
  <appSettings/>
  <connectionStrings>
</connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <roleManager enabled="true" />
    <membership>
      <providers>
        <remove name="AspNetSqlMembershipProvider"/>
        <add name="AspNetSqlMembershipProvider"
             type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
             connectionStringName="Login"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             applicationName="/"
             requiresUniqueEmail="false"
             passwordFormat="Hashed"
             maxInvalidPasswordAttempts="5"
             minRequiredPasswordLength="1"
             minRequiredNonalphanumericCharacters="0"
             passwordAttemptWindow="10"
             passwordStrengthRegularExpression="" />
      </providers>
    </membership>

    <authentication mode="Windows"/>
    <customErrors mode="On"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="PMAService.PMA">
        <endpoint binding="webHttpBinding" contract="PMAService.IPMA" behaviorConfiguration="web">
        </endpoint>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

login/x/y 运行良好,而 ReturnCounter 给出错误端点未找到

有什么办法可以解决这个问题吗

最佳答案

首先启用Tracing在您的服务上查看异常原因是什么。

此外,您还可以考虑增加服务器和客户端上的 ReaderQuotas,以便可以毫无问题地传递更大的数据。示例如下:

<system.serviceModel>    
<bindings>
<webHttpBinding>
          <binding maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
             <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                  maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                  maxNameTableCharCount="2147483647" />
            <security mode="None" />
          </binding>
        </webHttpBinding>
</bindings>
</system.serviceModel>   
 

我还在您的代码中看到您正在直接传递 Entity Framework 获取的对象。在某些情况下, Entity Framework 对象不会被反序列化,并可能导致异常。创建一个简单的 POCO,然后填充获取的数据并返回 POCO。

关于json - 未找到端点 WCF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10930199/

相关文章:

c# - 带有 MySql 和迁移的 Entity Framework 因 "max key length is 767 bytes"而失败

c# - 将参数传递给 Entity Framework 中的可重用表达式

entity-framework - 在哪里可以找到 ADO.NET Entity Framework 错误列表?

java - 如何将 json 代码获取到我的应用程序中

Android:如何通过服务发送图片

c# - SvcUtil.exe 与添加引用

asp.net - BuildManager.GetReferencedAssemblies 等效于非 Web 应用程序

java - JsonPath - 读取 Java Long 类型

java - 使用 GSON 解析 key - 对象 JSON

c# - Azure:使用 Full-IIS 进行 Web 角色内通信 (netTcpBinding)