Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One service, multiple endpoints, multiple bindings on WCF. Why can't I reach my endpoints?

I have a WCF service run by IIS. I would like to create two different clients (WPF and WP7), that are using the same service. The WPF client was already working with an endpoint using wsHttpBinding and https. Sadly WP7 doesn't do wsHttpBinding, only BasicHttpBinding. So I thought I would expose different endpoints for the two, so they could access the same service, but with different bindings and what not...

So here is my Web.config on IIS:

<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="TransportSecurity">
        <reliableSession enabled="true" />
          <security mode="TransportWithMessageCredential" >
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </wsHttpBinding>
      <basicHttpBinding>
        <binding name="BasicTransportSecurity">
           <security mode="Transport">
              <transport clientCredentialType="None"/>
           </security>
         </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SmartCook2.Server.ISmartCookServiceBehavior">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service behaviorConfiguration="SmartCook2.Server.ISmartCookServiceBehavior"
        name="SmartCook2.Server.SmartCookService">
        <endpoint address="WS" binding="wsHttpBinding" bindingConfiguration="TransportSecurity"
          name="WS" contract="SmartCook2.Server.ISmartCookService" />
        <endpoint address="Basic" binding="basicHttpBinding" bindingConfiguration="BasicTransportSecurity"
          name="Basic" contract="SmartCook2.Server.ISmartCookService" />
        <endpoint address="mex" binding="mexHttpsBinding" name="mex"
          contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
<connectionStrings>
    <add name="SmartCookDBEntities" connectionString="metadata=res://*/SmartCookContext.csdl|res://*/SmartCookContext.ssdl|res://*/SmartCookContext.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=RENDERBETYAR;initial catalog=SmartCookDB;integrated security=True;pooling=False;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

</configuration>

Now if I got it right the endpoints should be accessible on the following addresses:

https://localhost/IISHostedSmartCook/SmartCookService.svc/Basic
https://localhost/IISHostedSmartCook/SmartCookService.svc/WS
https://localhost/IISHostedSmartCook/SmartCookService.svc/mex

If I check them in my browser I get nothing. There's no exception, but no content either. Using the base address (till the .svc part) I get the default service page and I can access the wsdl and it is valid. It has the endpoints, my service's methods etc correctly as far as I can tell.

If I try to add the ServiceReference to my WP7 project is Visual Studio, I can only see my service under the base address (specific endpoint addresses return nothing). If I add it, the classes are generated about right, only I can't call any of my service's methods and I get the error message "There is no endpoint listening at this address". (This also happens if I use the service client's constructor requiring the endpoint's name.)

What am I doing wrong?

like image 819
Tenshiko Avatar asked Oct 24 '11 23:10

Tenshiko


People also ask

Can WCF service have multiple endpoints?

Sometimes in our mind the question arise; can we implement multiple service contract in WCF service? And the answer is, Yes we can. Service class implement multiple service interfaces, and then expose each service using a different endpoint.

How many endpoints can a WCF Service have?

The service configuration has been modified to define two endpoints that support the ICalculator contract, but each at a different address using a different binding.

Can a service have multiple endpoints?

As demonstrated in the Multiple Endpoints sample, a service can host multiple endpoints, each with different addresses and possibly also different bindings. This sample shows that it is possible to host multiple endpoints at the same address.

How many types of endpoints are there in WCF?

The service Web. config file has been modified to define two endpoints, each supporting the same ICalculator contract, but at different addresses using different bindings. The first endpoint is defined at the base address using a basicHttpBinding binding, which does not have security enabled.


2 Answers

Check here for detailed explanation.

What you will need to specify is the address like so in your endpoints:

  <service behaviorConfiguration="SmartCook2.Server.ISmartCookServiceBehavior"
    name="SmartCook2.Server.SmartCookService">
    <endpoint address="http://localhost/Service.svc/WS" binding="wsHttpBinding" bindingConfiguration="TransportSecurity"
      name="WS" contract="SmartCook2.Server.ISmartCookService" />
    <endpoint address="http://localhost/Service.svc/Basic" binding="basicHttpBinding" bindingConfiguration="BasicTransportSecurity"
      name="Basic" contract="SmartCook2.Server.ISmartCookService" />
    <endpoint address="" binding="mexHttpsBinding" name="mex"
      contract="IMetadataExchange" />
  </service>
like image 157
VoodooChild Avatar answered Oct 21 '22 07:10

VoodooChild


<services>
...
      <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
         <host>
            <baseAddresses>
               <add baseAddress="https://localhost/IISHostedSmartCook/SmartCookService.svc"/>
            </baseAddresses>
        </host>
   </service>
</services>
...
like image 40
RaphaelH Avatar answered Oct 21 '22 07:10

RaphaelH