under_score
under_score

Reputation: 57

Host WCF to existing MVC Web site

Things i have to do and already done :

  1. Add WCF service to an existing mvc web app. under some folder ex:/Service/Service1.svc

  2. Host the MVC site to IIS, completely functioning site tested.

    namespace WebApplication3.Service
    {
        public class Service1 : IService1
        {
            public string DoWork()
            {
                return "some string";
            }
        }
    }
    
    
    namespace WebApplication3.Service
    {
        [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            [WebInvoke(Method = "GET")]
            string DoWork();
        }
    }
    

and the web config :

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="transportsecurity">
      <security mode="Transport">
        <transport clientCredentialType="None"></transport>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

<services>
  <service name="WebApplication3.Service.Service1" behaviorConfiguration="mybehavior">
    <endpoint address="http://localhost/testsite/Service/Service1.svc" binding="basicHttpBinding" bindingConfiguration="transportsecurity" contract="WebApplication3.Service.IService1">
    </endpoint>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="mybehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
  multipleSiteBindingsEnabled="true" />

when i browse the service on IIS it shows not found error 404.

Thanks!

Upvotes: 1

Views: 371

Answers (1)

loopedcode
loopedcode

Reputation: 4893

Most likely the endpoint address is not correct/matching based on how you are hosting.

Just change the endpoint address to empty string.

<services>
  <service name="WebApplication3.Service.Service1" behaviorConfiguration="mybehavior">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="transportsecurity" contract="WebApplication3.Service.IService1">
    </endpoint>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
  </service>
</services>

Also, you have configured this to be https (transport security), so make sure you are using https url. For initial testing I would suggest first remove the security and have just work with basic binding. Once it working, then test with security.

Upvotes: 2

Related Questions