views:

245

answers:

3

I worked through building a WCF web service on my development machine. I built the service, created a test client, tested everything and it works. I was starting to feel pretty good about this WCF stuff. Then I got gutsy and moved it to my production server.

For now, the production server is on WinHost.com. I have my testing domain, www.MyDomain.com, created an application folder, /websvc, and copied the web service files into it. The service address is http://www.MyDomain.com/websvc/eval.svc

Now that I've moved to the production server I can't use the web service. I get this error - "This collection already contains an address with scheme http." I googled the message for solutions, tried a few but that only led to other errors. So I reset everything and I'm starting over.

Based on the service address above, what should my web.config look like? Specifically, how should my endpoints look in it?

Here is what I have now...

<configuration>
  <system.serviceModel>
    <services>
      <service name="EvalServiceLibrary.EvalService">
        <endpoint address="http://www.MyDomain.com:80/websvc/mex"
          binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="http://www.MyDomain.com:80/websvc/basic"
          binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
A: 

Hi, it's just mean that when you're hosting the service in IIS there is no need to specify the base address. It's already defined by IIS virtual directory. Simply replace your block with this:

<services>
  <service name="EvalServiceLibrary.EvalService">
    <endpoint address="mex"
      binding="mexHttpBinding" contract="IMetadataExchange" />
    <endpoint address="basic"
      binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" />
  </service>
</services>
Yuriy Khan
+1  A: 

Every time I've run into this, it's because IIS is configured for multiple virtual hosts by name (a common config in hosted scenarios). Here is a good way to fix it that's always worked for me- note that you need to explicitly and exactly define your endpoint addresses, including the proper hostname (which it looks like you more-or-less have).

I've filed connect bugs around this, and it's supposedly better for 4.0, but I haven't tried it yet.

nitzmahone
+1  A: 

Web service is now working and hosted on a third party service as described above. The web.config being used is inlcuded below.

Lesson learned: Writing the code for WCF web services isn't difficult but configuring the endpoints can be a tad challenging.

<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
-->
<configuration>

  <system.serviceModel>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="false">
      <!-- modified section here-->
      <baseAddressPrefixFilters>
        <add prefix="http://www.MyDomain.com:80/websvc/eval.svc"/&gt;
      </baseAddressPrefixFilters>
    </serviceHostingEnvironment>

    <services>
      <service behaviorConfiguration="ServiceBehavior" name="EvalServiceLibrary.EvalService">
        <endpoint address="" binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>
Scott