none
Getting an "Address property on ChannelFactory.Endpoint was null" exception with "webhttpbinding" and VS2008 pro

    Question

  • I just installed VS2008 Pro and the .NET framework 3.5 and the first thing i wanted to check out was the REST support in WCF.
    I created a WCF->WCF Service Library project in vs2008 which created a sample service with 2 endpoints (mexHttpBinding and wsHttpContextBinding). Pressing F5 runs the service hosting client app and i'm able to successfully call the GetData() test method.

    Using the VS tool to edit the app.config, i deleted both endpoints and created a new webHttpBinding one. I added a reference to System.ServiceModel and added the following attribute to the GetData method in the IService1interface:

    [OperationContract]
    [WebGet( UriTemplate = "/test/{value}" )]
    string GetData( int value );

    Pressing F5 and trying to invoke the GetData method via the webhttpbinding endpoint raises the following exception:

    The Address property on ChannelFactory.Endpoint was null.  The ChannelFactory's Endpoint must have a valid Address specified.
       at System.ServiceModel.ChannelFactory.CreateEndpointAddress(ServiceEndpoint endpoint)
       at System.ServiceModel.ClientBase`1.CreateChannel()
       at System.ServiceModel.ClientBase`1.CreateChannelInternal()
       at System.ServiceModel.ClientBase`1.get_Channel()
       at Service1Client.GetData(Int32 value)


    If i try calling the service via a web browser, i get the following error:

    URL: http://localhost:8731/Design_Time_Addresses/test_wcf2/Service1/test/0
    Response:

    <Fault>
        <Code>
            <Value>Sender</Value>
            <Subcode>
                <Value>a: DestinationUnreachable</Value>
            </Subcode>
        </Code>
        <Reason>
            <Text xml:lang="en-US">
                The message with To 'http://localhost:8731/Design_Time_Addresses/test_wcf2/Service1/test/0' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher.  Check that the sender and receiver's EndpointAddresses agree.
            </Text>
        </Reason>
    </Fault>

    I tried to change various things in the endpoint config as well as removing the UriTemplate attribute in the service contract with no success. My current serviceModel section in App.config is:

      <system.serviceModel>
        <services>
          <service behaviorConfiguration="test_wcf2.Service1Behavior" name="test_wcf2.Service1">
            <endpoint address="" binding="webHttpBinding" bindingConfiguration=""
              bindingName="web binding" contract="test_wcf2.IService1" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8731/Design_Time_Addresses/test_wcf2/Service1" />
              </baseAddresses>
            </host>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="test_wcf2.Service1Behavior">
              <!-- 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="True" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>


    Any idea what i'm doing wrong? It seems really straightforward, but i've spent a few hours on it already and i can't seem to make it work. Should i not use the VS2008 wizard and create the service programmatically?

    Thank you,

    pierre

    Saturday, January 12, 2008 12:08 AM

Answers

  •  

    First  - you have to change the parameter from int to string - UriTemplate dispatching only supports strings.

     

    Second - you need to add a new endpoint behavior with a webHttpBehavior and then link that to the endpoint:

     

     

    <endpointBehaviors>

    <behavior name="webBehavior">

    <webHttp/>

    </behavior>

    </endpointBehaviors>

    Saturday, January 12, 2008 12:54 AM
    Moderator

All replies

  •  

    First  - you have to change the parameter from int to string - UriTemplate dispatching only supports strings.

     

    Second - you need to add a new endpoint behavior with a webHttpBehavior and then link that to the endpoint:

     

     

    <endpointBehaviors>

    <behavior name="webBehavior">

    <webHttp/>

    </behavior>

    </endpointBehaviors>

    Saturday, January 12, 2008 12:54 AM
    Moderator
  • Thank you for your answer. I implemented the changes you mentioned and still have the same issue.

    1. GetData now expects a string:

            [OperationContract]
            [WebGet( UriTemplate = "/test/{value}" )]
            string GetData( string value );

    2. This is my updated serviceModel:

      <system.serviceModel>
        <services>
          <service behaviorConfiguration="test_wcf2.Service1Behavior" name="test_wcf2.Service1">
            <endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding"
              bindingConfiguration="" bindingName="web binding" contract="test_wcf2.IService1" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8731/Design_Time_Addresses/test_wcf2/Service1" />
              </baseAddresses>
            </host>
          </service>
        </services>
        <behaviors>
          <endpointBehaviors>
            <behavior name="webBehavior">
              <webHttp />
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="test_wcf2.Service1Behavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>

    pierre
    Saturday, January 12, 2008 2:09 AM
  • Does it work from your browser?  I am fairly certain the mex enabled WcfClient

    won't work  once webHttpBinding is enabled.

    Saturday, January 12, 2008 5:21 AM
    Moderator
  • I removed the mex endpoint. The only endpoint i want to test is webhttpbinding.

    The thing is, i tried from a browser and it now works! I still get the same exception than previously when calling it from the hosting app, but that's not a big deal.

    Thank you for your help!

    pierre
    Monday, January 14, 2008 8:02 PM
  • thanks for the info...had the same problem, fixed it the same way; works great.

     

    Thursday, October 09, 2008 6:30 PM
  • I'm still getting this error despite implementing all of the solutions mentioned here

    Contract:

    [OperationContract]
            [WebInvoke(
                Method = "POST",
                ResponseFormat = WebMessageFormat.Json,
                BodyStyle = WebMessageBodyStyle.Wrapped,
                UriTemplate = "/Authenticate")]
            User Authenticate(string uname, string pwd);
    Web.config

       <services>
          <service name="MyServices.UserService" behaviorConfiguration="ServiceBehavior">
            <endpoint address="" binding="webHttpBinding" contract="MyServices.IUserService" behaviorConfiguration="webBehavior" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="webBehavior">
              <webHttp/>
            </behavior> 
          </endpointBehaviors>
        </behaviors>

    This exception is thrown when I attempt to test the service WcfTestClient.exe, if I attempt to call up this service in the browser (http://localhost/MyServices/User.svc/Authenticate) I get a page that says "Method Not Allowed"

    Any idea what could be causing this?
    Thursday, April 30, 2009 8:19 PM
  • When you point the browser to the method, it will use a GET request. The Method proprty of the [WebInvoke] attribute specifies that the operation will only respond to POST requests.
    WcfTestClient doesn't work for REST (i.e., WebHttpBinding-based) services, since it relies on metadata (which isn't available in REST services) to create the requests.

    Thursday, April 30, 2009 10:50 PM
  • Thx~ Jon I slove the problem by your advice.
    I saw, I came , I conquered!
    Monday, January 11, 2010 9:40 AM
  • I also found that the service contract name is case sensitive. If I am wrong about this, please let me know, but I, for my sake, was struglling with exactly that.

     

    Friday, May 14, 2010 10:29 AM
  • Hi,

    I'm still getting the same problem even after following all the above. Please help. this is my web.config file.

    <?xml version="1.0" encoding="utf-8"?>

    <configuration>

      <system.serviceModel>

        <services>

          <service behaviorConfiguration="PSIAStreaming.StreamingBehavior" name="PSIAStreaming.Streaming">

            <endpoint address="" binding="webHttpBinding"

            bindingConfiguration="" bindingName="web binding" contract="PSIAStreaming.IStreaming" />

            <host>

              <baseAddresses>

                <add baseAddress="http://localhost:8484/" />

              </baseAddresses>

            </host>

          </service>

        </services>

        <behaviors>

          <endpointBehaviors>

            <behavior name="PSIAStreaming.StreamingBehavior">

              <webHttp />

            </behavior>

          </endpointBehaviors>

          <serviceBehaviors>

            <behavior name="PSIAStreaming.StreamingBehavior">

              <serviceMetadata httpGetEnabled="true" />

              <serviceDebug includeExceptionDetailInFaults="true" />

            </behavior>

          </serviceBehaviors>

        </behaviors>

      </system.serviceModel>

        <system.web>

            <identity impersonate="false" />

        </system.web>

        <system.webServer>

            <defaultDocument enabled="true" />

        </system.webServer>

    </configuration>

     

    Thanks

    Sureshthi

     

    Wednesday, May 19, 2010 9:49 AM
  • Hi all ,

    I am also getting same problem while trying to execute my app using service reference.but my service is executing properly in direct execution.Please help me in this.below i am providing my codes.

    Service web.config:

    <system.serviceModel>
        <services>
            <service behaviorConfiguration="ServiceBehavior" name="Service">
            <endpoint address="http://localhost:2045/wcftest/Service.svc"
            behaviorConfiguration="wcftestconfig" binding="webHttpBinding" contract="IService" />
       </service>
      </services>
            <behaviors>
                <endpointBehaviors>
                    <behavior name="wcftestconfig">
                        <webHttp/>
                    </behavior>
                </endpointBehaviors>
         
                <serviceBehaviors>
                    <behavior name="ServiceBehavior">
                         <serviceMetadata httpGetEnabled="true"/>
                         <serviceDebug includeExceptionDetailInFaults="false"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
        </system.serviceModel>

     

    Service Contract Interface:

    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        [WebInvoke(Method = "GET")]
        List<DisplayCompanyOverviewResult> GetCompanyDetails();
      
    }

     

    Interface Method Declaration:

     

     public List<DisplayCompanyOverviewResult> GetCompanyDetails()
        {
            AonDataContext aon = new AonDataContext();
           
            List<DisplayCompanyOverviewResult> overview = aon.DisplayCompanyOverview().ToList();
            return overview;
        }

     

    Service Calling from UI:

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using ServiceReference1;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ServiceClient client = new ServiceClient();
            List<DisplayCompanyOverviewResult> result = client.GetCompanyDetails().ToList();

        }
    }

    here i am getting error like "The Address property on Channel Factory.Endpoint was null.  The Channel Factory's Endpoint must have a valid Address specified. "

    Friday, January 07, 2011 9:12 AM