none
The Address property on ChannelFactory.Endpoint was null. The ChannelFactory's Endpoint must have a valid Address specified.

    Question

  • 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:24 AM

Answers

  • The service is using webHttpBinding, which means it is a REST service. But your client is using a custom binding, and it's using SOAP message encoding. So the client and service doesn't agree with each other.

    Why do you have to use channel factory? Channel factory is not recommended to use against REST services. Please use HttpWebRequest instead, or for a simple GET request, you can simply use WebClient.

    To use WebClient, remove all WCF settings in the client configuration. They're not needed. Delete the client proxy class and the channel factory related code. Then write:

    WebClient webClient = new WebClient()

    string result = webClient.DownloadString("http://localhost:2045/wcftest/Service.svc/GetCompanyDetails");

    Then the result variable will contain the response obtained from the service. If it is a JSON response, you can go on to use DataContractJsonSerializer to deserialize it to your own class. As you can see, this approach is much easier compared to channel factory.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    • Marked as answer by Yi-Lun Luo Thursday, January 13, 2011 9:33 AM
    Monday, January 10, 2011 6:31 AM

All replies

  • Hello,

    you can't use Add service reference to create proxy for REST service. REST service can be invoked only directly through WebRequest or by creating proxy manually (by using ChannelFactory). Both ways are described on this blog.

    Best regards,
    Ladislav

    Friday, January 07, 2011 11:50 AM
  • hi now i am getting

    Server Error in '/AonApplication' Application.

    The remote server returned an error: (404) Not Found.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Net.WebException: The remote server returned an error: (404) Not Found.

    Source Error:

    Line 1142:    
    Line 1143: public AonService.UpdateStatusResult[] UpdateStatus(string CompanyID, string Status) {
    Line 1144: return base.Channel.UpdateStatus(CompanyID, Status);
    Line 1145: }
    Line 1146:

    Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\aonapplication\224ba4dd\8c924f87\App_WebReferences.as-fcn5e.0.cs    Line: 1144
    Friday, January 07, 2011 12:26 PM
  • Hello,

    use Fiddler and check the traffic between your client and service. Check that request has correct address.

    Best regards,
    Ladislav

    Friday, January 07, 2011 3:42 PM
  • Hello, your service address is http://localhost:2045/wcftest/Service.svc. Note there's no /AonApplication. Please make sure the service address is correct. Also try this in the broswer: http://localhost:2045/wcftest/Service.svc/GetCompanyDetails
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    Monday, January 10, 2011 5:28 AM
  • ng to hi while i am trying with channel factory class i am getting below error......

    Server Error in '/AONApplication' Application.

    The remote server returned an error: (404) Not Found.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Net.WebException: The remote server returned an error: (404) Not Found.

    Source Error:

    Line 62:     ChannelFactory<IGenerationcodes> factory = new ChannelFactory<IGenerationcodes>("WebHttpBinding_IGenerationcodes");
    Line 63: var proxy = factory.CreateChannel();
    Line 64: var response = proxy.UpdateStatus(CompanyID, Status);
    Line 65: ((IDisposable)proxy).Dispose();
    Line 66: //GenerationcodesClient Aon = new GenerationcodesClient();

    Source File: c:\saggezza.repositoryhosting.com\svn\Aon_New\AONApplication\Forms\Home.aspx.cs    Line: 64

    Stack Trace:

    [WebException: The remote server returned an error: (404) Not Found.]
    System.Net.HttpWebRequest.GetResponse() +5313085
    System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +54

    [EndpointNotFoundException: There was no endpoint listening at http://localhost/AonService/Rest_Webservices/Generationcodes.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.]
    System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +7594687
    System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +275
    AonService.IGenerationcodes.UpdateStatus(String CompanyID, String Status) +0
    login.btnInactive_Click(Object sender, EventArgs e) in c:\saggezza.repositoryhosting.com\svn\Aon_New\AONApplication\Forms\Home.aspx.cs:64
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
    Monday, January 10, 2011 5:38 AM
  • As mentioned above, first please test in the browser instead of your client application. Make sure the address is correct. For example, with the code you posted above, the address should be http://localhost:2045/wcftest/Service.svc/GetCompanyDetails. There's no /AONApplication. Also in the client application, try to use WebClient or HttpWebRequest/Response to access the service directly, without a channel factory.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    Monday, January 10, 2011 5:44 AM
  • hi vardhi..

    You and set endpoint address through code.

    Create an instance of ChannelFactory<T> class and assign the address of your endpoint.

    Ex.

    ChannelFactory<IInterface> cf = new ChannelFactory<IInterface>("Your ServiceName");
    
    cf.Endpoint.Address = new EndpointAddress("Your endpoint address");
    

     

     

     

     

     

     


    Regards, Hiren Bharadwa
    Monday, January 10, 2011 5:57 AM
  • hi and i am using it for JSON formate..Please suggest me what kind of changes i have to make for JSON and using channel factory concept..i am pretty new to this stuff..and Please check my privous code what i am using exclty..and here i am posting my UI web.config file..please check and suggest me what exactly i have to do..
    UI Web.config...

     <system.serviceModel>
      <bindings>
       <customBinding>
        <binding name="WebHttpBinding_IGenerationcodes">
         <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
          messageVersion="Soap12" writeEncoding="utf-8">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
           maxBytesPerRead="4096" maxNameTableCharCount="16384" />
         </textMessageEncoding>
          <httpTransport >
          </httpTransport>
        </binding>
       </customBinding>
      </bindings>
      <client>
       <endpoint address="http://localhost:80/AonService/Rest_Webservices/Generationcodes.svc" binding="customBinding" bindingConfiguration="WebHttpBinding_IGenerationcodes"
        contract="AonService.IGenerationcodes" name="WebHttpBinding_IGenerationcodes" />
      </client>
     </system.serviceModel>

    Service Web.Config..

    <system.serviceModel>
            <bindings>
                <webHttpBinding>
                    <binding name="SecureBinding" allowCookies="true" maxReceivedMessageSize="2147483647" maxBufferPoolSize="99999999" closeTimeout="00:59:00" openTimeout="00:59:00" receiveTimeout="00:59:00" sendTimeout="00:59:00">
                        <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647">
                        </readerQuotas>
                    </binding>
                </webHttpBinding>
            </bindings>
           
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
            <behaviors>
       
                <endpointBehaviors>
                    <behavior name="AjaxGenerationcodesBehavior">
                        <webHttp/>
                    </behavior>
                </endpointBehaviors>
                <serviceBehaviors>
                    <behavior name="GenerationcodesBehavior">
                        <serviceMetadata httpGetEnabled="true"/>
                        <serviceDebug includeExceptionDetailInFaults="false"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <services>
                <service behaviorConfiguration="GenerationcodesBehavior" name="Generationcodes">
            <host>

              <baseAddresses>
                <add baseAddress="http://localhost:80/AonService/Rest_Webservices/Generationcodes.svc"/>
              </baseAddresses>
            </host>
                    <endpoint address="" binding="webHttpBinding" bindingConfiguration="SecureBinding" contract="IGenerationcodes" behaviorConfiguration="AjaxGenerationcodesBehavior">
                        <identity>
                            <dns value="localhost:456"/>
                        </identity>
                    </endpoint>
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
                </service>
            </services>
        </system.serviceModel>

     

    this is the stuff i am usign and i am using channel factory in UI reference....

    Monday, January 10, 2011 6:04 AM
  • The service is using webHttpBinding, which means it is a REST service. But your client is using a custom binding, and it's using SOAP message encoding. So the client and service doesn't agree with each other.

    Why do you have to use channel factory? Channel factory is not recommended to use against REST services. Please use HttpWebRequest instead, or for a simple GET request, you can simply use WebClient.

    To use WebClient, remove all WCF settings in the client configuration. They're not needed. Delete the client proxy class and the channel factory related code. Then write:

    WebClient webClient = new WebClient()

    string result = webClient.DownloadString("http://localhost:2045/wcftest/Service.svc/GetCompanyDetails");

    Then the result variable will contain the response obtained from the service. If it is a JSON response, you can go on to use DataContractJsonSerializer to deserialize it to your own class. As you can see, this approach is much easier compared to channel factory.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    • Marked as answer by Yi-Lun Luo Thursday, January 13, 2011 9:33 AM
    Monday, January 10, 2011 6:31 AM
  • HI Yi...thanq very much a million times.........this was resolved and i am very much happy that u guys are doing really gr8 stuff for customers...once again thanq very much...............
    Monday, January 10, 2011 8:02 AM
  • Hey Yi..can u have any samples for how to bind JSON data to datagrid in code behind..please help me if u have any.thig...
    Monday, January 10, 2011 8:14 AM
  • I don't have a particular sample to combine JSON and ASP.NET data binding. But after you deserialize the data to a CLR object, you should be able to use the standard ASP.NET ObjectDataSource. Alternatively, since you're using JSON, you can invoke the service on the client side using jQuery, and then display the data using jQuery Templates. Our team has a blog post about jQuery accessing WCF Data Services (which are REST services): http://blogs.msdn.com/b/windows-azure-support/archive/2010/11/16/azure-bing-maps-accessing-odata-services-from-ajax-clients.aspx, as well as how to use jQuery Templates: http://blogs.msdn.com/b/windows-azure-support/archive/2010/10/28/azure-bing-maps-displaying-structured-data-in-rich-html-applications-with-jquery-templates.aspx.

    If you have ASP.NET specific questions, you can ask on the ASP.NET forum: http://forums.asp.net/.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    Monday, January 10, 2011 9:56 AM
  • The advice "ChannelFactory is not recommended to use agains REST services" is at odds with MSDN topic "How to: Create a Basic WCF Web HTTP Service", http://msdn.microsoft.com/en-us/library/bb412178.aspx, which demostrates exactly that.

    Can you please provide a reference for this advice, as I haven't located anything yet which validates that statement. Many thanks!


    Stuart Celarier | Principal Consultant, Neudesic Microsoft Regional Director & MVP Connected Systems http://visualstuart.net | 503.732.0247
    Sunday, November 13, 2011 5:50 PM