【问题标题】:Insert operation with WCF rest fails everytime....每次使用 WCF 休息的插入操作都会失败....
【发布时间】:2012-05-15 02:39:51
【问题描述】:

您好,我在我的应用程序中使用 WCF Rest 并采用分层架构。我的数据流层次结构如下:

Data Layer -> Linq2Sql
||
Business Layer
||
WCF Rest Service
||
ASPX Pages

我通过 JQuery 使用 JSON 来选择/删除和代码隐藏以插入/更新,以便我可以使用 WCF 服务通过我的业务层将 .Net 对象传递到数据库库(以检查我是否有它们的业务逻辑。)。

例如,我在我的业务层加密密码和解密密码并将其发送到数据层。无论如何,这不是问题。问题在于 WCF 服务配置设置。每次我得到独特的例外,比如:

  1. 404 错误请求。
  2. http://localhost/Service.svc 上没有可以接受消息的端点侦听。
  3. 在服务模型客户端配置部分中找不到引用合同“xxx”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素 等等……

我试过的是

  1. 根据Tom Haigh 建议的答案。 受保护的 Save_Click(sender,e) {

    var 用户 = 新用户 { 登录=登录。值, 密码 = pwd.Value, 实名=实名.值, AccessRight = accessrights.Value, CustomAccesRight = customaccessrights.Value };

        var remoteAddress = new EndpointAddress("http://localhost:2360/UserService.svc");
    
        using (var client = new UserServiceClient(new BasicHttpBinding(), remoteAddress))
        {
            //set timeout
            client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 0, 0, 10000);
    
            //call ws method
            client.Insert(user);
        } //using
    

}

  1. 我也尝试过删除,得到错误 400

    受保护的 Save_Click(sender,e) {

    var 用户 = 新用户 { 登录=登录。值, 密码 = pwd.Value, 实名=实名.值, AccessRight = accessrights.Value, CustomAccesRight = customaccessrights.Value };

        var remoteAddress = new EndpointAddress("http://localhost:2360/UserService.svc");
    
       var client = new UserServiceClient(new BasicHttpBinding(), remoteAddress);
    
            //set timeout
            client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 0, 0, 10000);
    
            //call ws method
            client.Insert(user);
    

}

我的服务配置文件:

<system.serviceModel>
    <services>
      <service name="EnergyManagementControl.WcfSvc.UserService"  behaviorConfiguration="ServiceBehaviour" >
        <endpoint name="" binding="webHttpBinding"   contract="EnergyManagementControl.WcfSvc.IUserService" address="http://localhost:2360/UserService.Svc"   behaviorConfiguration="web"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour"  >
          <serviceMetadata  httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

我的客户端配置文件

<system.serviceModel>
    <client>
      <endpoint
        name = "Receptor"
         address="http://localhost:2360/UserService.Svc" 
        binding = "wsHttpBinding"
        contract="IUserService"
    />
    </client>
  </system.serviceModel>

但似乎没有任何帮助。我知道它的配置错误,请帮助我。此外,根据我的场景对 WCF 休息的任何简要参考都会有很大帮助.....

请不要将 WCF 创建为 WCF 服务应用程序,并且是我的 Web 应用解决方案中的一个项目。请参见下图:

另外我在 WebDev 服务器上遇到错误,而不是在 IIS 或 Cassini 上

【问题讨论】:

    标签: c# asp.net wcf-rest


    【解决方案1】:

    对于 REST 服务的 WCF 使用我不能说太多,但是您的服务和客户端端点绑定不匹配。 WCF 使用绑定来查找匹配的端点。

    【讨论】:

      猜你喜欢
      • 2011-06-30
      • 2014-05-11
      • 1970-01-01
      • 2015-02-23
      • 2014-04-14
      • 2019-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多