简体   繁体   中英

Error 404 When calling Restful Wcf Service

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" />

Based on a brief review, the service section of the config file seems to be missing the baseAddresses element.

    <host>
      <baseAddresses>
        <add baseAddress="https://localhost:3522/AccountService.svc" />
      </baseAddresses>
    </host>

In addition, you may want to consider enabling WCF Tracing and Logging, so you can review the WCF service startup events for any errors. The following link provides a good overview:

http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx

Final note: since your service binding has [security mode="Transport"], make sure your server side certificate is configured correctly to support ssl.

Regards,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM