错误404当调用宁静的WCF服务 [英] Error 404 When calling Restful Wcf Service

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

问题描述

我一次又一次地做了搜索,但我真的不知道我缺少什么。我有WCF方法调用的服务回报错误404后,资源无法找到。

这样的网址:本地主机:3522 / AccountService.svc / accountbalance / 1

我运行它从视觉与IIS 8防爆preSS。

这样的WCF方法

  [的ServiceContract]
公共接口IAccountService
{
    [OperationContract的]
    [WebGet(UriTemplate =accountbalance / {帐户ID})]
    十进制GetAccountBalance(字符串帐户ID);
}
 

这是我的web.config

 <绑定>
  < / basicHttpBinding的>
  <的WebHttpBinding>
    <绑定名称=的WebHttpBinding>
      <安全模式=运输>
        <交通运输clientCredentialType =窗口proxyCredentialType =的Windows/>
      < /安全>
    < /装订>
  < /的WebHttpBinding>
< /绑定>

<服务>
  <服务behaviorConfiguration =ProfileServiceDefaultBehavior
    NAME =MyWcfService.AccountService>
    <终点behaviorConfiguration =RestFulBehavior绑定=的WebHttpBinding
      bindingConfiguration =的WebHttpBindingNAME =AccountServiceEndpoint
      bindingName =AccountServiceBinding合同=MyWcfService.IAccountService/>
    <端点地址=MEXbehaviorConfiguration =绑定=mexHttpBinding
      合同=IMetadataExchange接口/>
  < /服务>
< /服务>

<行为>
  < endpointBehaviors>
    <行为NAME =RestFulBehavior>
      < webHttp automaticFormatSelectionEnabled =真/>
    < /行为>
  < / endpointBehaviors>
  < serviceBehaviors>
    <行为NAME =ProfileServiceDefaultBehavior>
      < serviceMetadata httpGetEnabled =真/>
      < serviceDebug includeExceptionDetailInFaults =真/>
    < /行为>
  < / serviceBehaviors>
< /行为>

< serviceHostingEnvironment aspNetCompatibilityEnabled =真multipleSiteBindingsEnabled =真/>
 

解决方案

我通过2种方式解决了这个问题:

  1. 传输安全模式, SSL 必须启用和服务必须在SSL被调用channed。
  2. TransportCredentialOnly 安全模式,REST式服务工作正常 HTTP

@adkSerenity:感谢您的SSL建议,并跟踪

最好的问候, 武

I did the search again and again but I don't really know what am I missing. I have WCF method and after calling, the service return with error 404, resource can not be found.

The url like this: localhost:3522/AccountService.svc/accountbalance/1

I run it from Visual with IIS 8 Express.

The WCF method like this

[ServiceContract]
public interface IAccountService
{
    [OperationContract]
    [WebGet(UriTemplate = "accountbalance/{accountId}")]
    decimal GetAccountBalance(string accountId);
}

And this is my web.config

<bindings>
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="WebHttpBinding">
      <security mode="Transport">
        <transport clientCredentialType="Windows" proxyCredentialType="Windows" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>

<services>
  <service behaviorConfiguration="ProfileServiceDefaultBehavior"
    name="MyWcfService.AccountService">
    <endpoint behaviorConfiguration="RestFulBehavior" binding="webHttpBinding"
      bindingConfiguration="WebHttpBinding" name="AccountServiceEndpoint"
      bindingName="AccountServiceBinding" contract="MyWcfService.IAccountService" />
    <endpoint address="mex" behaviorConfiguration="" binding="mexHttpBinding"
      contract="IMetadataExchange" />
  </service>
</services>

<behaviors>
  <endpointBehaviors>
    <behavior name="RestFulBehavior">
      <webHttp automaticFormatSelectionEnabled="true" />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="ProfileServiceDefaultBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

解决方案

I resolved the issue by 2 ways:

  1. For Transport security mode, SSL must be enabled and the service must be call in SSL channed.
  2. For TransportCredentialOnly security mode, the Restful service works fine with http.

@adkSerenity: thanks for the SSL suggestion, and tracing.

Best Regards, Vu

这篇关于错误404当调用宁静的WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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