none
A binding instance has already been associated to listen URI. RRS feed

  • Question

  • Hello.

    I am creating a mobile app connected to a WCF service, as explained in here :

    https://social.msdn.microsoft.com/Forums/en-US/3afcb0ce-300a-4621-900b-2b4fc40092e6/webconfig-file-format?forum=wcf

    Now, I have tried everything, and each time I get a different error.

    I need to be able to communicate to a third party DLL via my app and the service. I have set up the app to communicate to this dll but I am having issues with my WCF service's Web.Config file, which looks like this :

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <system.web>
        <compilation debug="true" targetFramework="4.5">
          <assemblies>
            <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
          </assemblies>
        </compilation>
        <httpRuntime targetFramework="4.5" />
      </system.web>
      <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
         <behaviors>
          <serviceBehaviors>
            <behavior name="DefaultBehavior">
              <serviceDebug includeExceptionDetailInFaults="true"/>
              <serviceMetadata httpGetEnabled="true"/>
            </behavior>
          </serviceBehaviors>
     </behaviors>
        <services>
           <!--This section is optional with the default configuration-->
            <!--model introduced in .NET Framework 4--> 
          <service name= 'Prosound_Service.DataService' behaviorConfiguration="DefaultBehavior">
    
             <!--This endpoint is exposed at the base address provided by host:     -->  
            <endpoint address=""
                      binding="wsHttpBinding"
                      contract='Prosound_Service.IService1' 
            listenUri="/"/>
    
             <endpoint address="mex"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange" 
            listenUri="/"/>
          
        
        
            </service>
        </services>
        
      </system.serviceModel>
      <connectionStrings>
        <add name="Umbrella_ProsoundEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=htg\umbrella;initial catalog=Umbrella_Prosound;user id=0022;password=hannes123;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
      </entityFramework>
    </configuration>

    The error I get is:

    A binding instance has already been associated to listen URI. When 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' is set to true in configuration, the endpoints are required to specify a relative address. If you are specifying a relative listen URI on the endpoint, then the address can be absolute. To fix this problem, specify a relative uri for endpoint.

    I do not know what to do, as my WCF skills are quite limited. I have done numerous searches on all the errors I got and I keep hitting my head against the wall of another error.

    Can someone please help me?

    Tuesday, August 18, 2015 7:50 AM

Answers

  • Hi HanneSThEGreaT,

    According to your description, If you want to develop a mobile app connected to a WCF service? If so, as far as I know the WCF Service must be as Restful-style which one service can support json data type.

    So, in our web.config file we need to use webhttpbinding. Code shown below:

    <system.serviceModel>
        <bindings>
          <webHttpBinding>
            <binding name="webBingding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                             maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
            </binding>
          </webHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="mySerBeh">
              <serviceMetadata httpGetUrl="mex" httpGetEnabled="true"/>
              <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="False"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="webHttpendBehavior">
              <webHttp/>
            </behavior>     
        </endpointBehaviors>
        </behaviors>
        <services>
          <service name="Service.Class1" behaviorConfiguration="mySerBeh">
            <host>
              <baseAddresses>
                <add baseAddress="http://LocalHost:7789/MySericeDemo"/>
              </baseAddresses>
            </host>
            <endpoint address="" binding="webHttpBinding" bindingConfiguration="webBingding"
                       contract="Contract.IService" behaviorConfiguration="webHttpendBehavior">
            </endpoint>
          </service>
        </services>
      </system.serviceModel>

    Then my service file like below:

    namespace Service
    {
        public class Class1 : IService
        {        
            public string postMostStr(string streamlength, Stream getStream)
            {
                try
                {
                    int bylength = Convert.ToInt32(streamlength);
                    byte[] resultByte = new byte[bylength];
                    getStream.Read(resultByte, 0, resultByte.Length);
                    Console.WriteLine(Encoding.UTF8.GetString(resultByte));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                Console.WriteLine("success!");
                return "success";
            }    
        }
    }

    My Iservice file like below:

    namespace Contract
    {
        [ServiceContract]
        public interface IService
        {              
            [OperationContract]
            [WebInvoke(Method="POST",UriTemplate="postMostStr/{streamLength}",BodyStyle=WebMessageBodyStyle.Bare)]
            string postMostStr(string streamLength, Stream getStream);        
        }
    }

    And I host my WCF Restful Service in a console application.

    namespace WCFRestful
    {
        class Program
        {
            static void Main(string[] args)
            {           
                try
                {
                    using (WebServiceHost host = new WebServiceHost(typeof(Class1)))
                    {
                        host.Opened += delegate
                        {
                            Console.WriteLine("server running...");
                        };
                        host.Open();
                        Console.ReadLine();
                    }
    
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    Console.ReadLine();
                }
            }
        }
    }

    And I test it with a console application, like below:

    namespace Test
    {
        class Program
        {
            static void Main(string[] args)
            {          
                try
                {
                    string strPost = "hello here is my test app" + "By doing this, we can try to cater"
                        + " to different set of clients. RESTful "                 
                        + "I will also cover how you can test your REST based service using a fiddler tool. ";
                    byte[] buffer = Encoding.UTF8.GetBytes(strPost);
                    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://LocalHost:7789/MySericeDemo/postMostStr/" + buffer.Length);
                    request.Method = "POST";
                    request.ContentType = "text/plain";
                    request.ContentLength = buffer.Length;
                    System.IO.Stream requestStream = request.GetRequestStream();
                    requestStream.Write(buffer, 0, buffer.Length);
                    requestStream.Close();
                    System.IO.Stream getStream = request.GetResponse().GetResponseStream();
                    byte[] resultByte = new byte[200];
                    getStream.Read(resultByte, 0, resultByte.Length);
                    Console.WriteLine(Encoding.UTF8.GetString(resultByte));
                  
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                Console.ReadLine();
            }
        }
    }
    

    For more information, please refer to the following articles:

    1.How to Create WCF REST Service for Mobile App

    I hope that will be helpful to you.

    Best Regards,

    Grady

    • Marked as answer by HanneSThEGreaT Wednesday, August 19, 2015 12:48 PM
    Tuesday, August 18, 2015 10:03 AM
    Moderator

All replies

  • I tried to add a base address as well:

     <host>
           <baseAddresses>
              <add baseAddress="http://agilesoft.dyndns.org/Test_Service/" />
           </baseAddresses>
       </host>

    and changed my endpoints to :

           <!--This endpoint is exposed at the base address provided by host:     -->  
            <endpoint address="TestService.svc"
                      binding="wsHttpBinding"
                      contract='Prosound_Service.IService1' 
            />
    
             <endpoint address="mex"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange" 
            />

    And now I get resource not found.

    I do not know what else to except for burning my computer or jump off a bridge

    Tuesday, August 18, 2015 9:42 AM
  • Hi HanneSThEGreaT,

    According to your description, If you want to develop a mobile app connected to a WCF service? If so, as far as I know the WCF Service must be as Restful-style which one service can support json data type.

    So, in our web.config file we need to use webhttpbinding. Code shown below:

    <system.serviceModel>
        <bindings>
          <webHttpBinding>
            <binding name="webBingding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                             maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
            </binding>
          </webHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="mySerBeh">
              <serviceMetadata httpGetUrl="mex" httpGetEnabled="true"/>
              <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="False"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="webHttpendBehavior">
              <webHttp/>
            </behavior>     
        </endpointBehaviors>
        </behaviors>
        <services>
          <service name="Service.Class1" behaviorConfiguration="mySerBeh">
            <host>
              <baseAddresses>
                <add baseAddress="http://LocalHost:7789/MySericeDemo"/>
              </baseAddresses>
            </host>
            <endpoint address="" binding="webHttpBinding" bindingConfiguration="webBingding"
                       contract="Contract.IService" behaviorConfiguration="webHttpendBehavior">
            </endpoint>
          </service>
        </services>
      </system.serviceModel>

    Then my service file like below:

    namespace Service
    {
        public class Class1 : IService
        {        
            public string postMostStr(string streamlength, Stream getStream)
            {
                try
                {
                    int bylength = Convert.ToInt32(streamlength);
                    byte[] resultByte = new byte[bylength];
                    getStream.Read(resultByte, 0, resultByte.Length);
                    Console.WriteLine(Encoding.UTF8.GetString(resultByte));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                Console.WriteLine("success!");
                return "success";
            }    
        }
    }

    My Iservice file like below:

    namespace Contract
    {
        [ServiceContract]
        public interface IService
        {              
            [OperationContract]
            [WebInvoke(Method="POST",UriTemplate="postMostStr/{streamLength}",BodyStyle=WebMessageBodyStyle.Bare)]
            string postMostStr(string streamLength, Stream getStream);        
        }
    }

    And I host my WCF Restful Service in a console application.

    namespace WCFRestful
    {
        class Program
        {
            static void Main(string[] args)
            {           
                try
                {
                    using (WebServiceHost host = new WebServiceHost(typeof(Class1)))
                    {
                        host.Opened += delegate
                        {
                            Console.WriteLine("server running...");
                        };
                        host.Open();
                        Console.ReadLine();
                    }
    
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    Console.ReadLine();
                }
            }
        }
    }

    And I test it with a console application, like below:

    namespace Test
    {
        class Program
        {
            static void Main(string[] args)
            {          
                try
                {
                    string strPost = "hello here is my test app" + "By doing this, we can try to cater"
                        + " to different set of clients. RESTful "                 
                        + "I will also cover how you can test your REST based service using a fiddler tool. ";
                    byte[] buffer = Encoding.UTF8.GetBytes(strPost);
                    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://LocalHost:7789/MySericeDemo/postMostStr/" + buffer.Length);
                    request.Method = "POST";
                    request.ContentType = "text/plain";
                    request.ContentLength = buffer.Length;
                    System.IO.Stream requestStream = request.GetRequestStream();
                    requestStream.Write(buffer, 0, buffer.Length);
                    requestStream.Close();
                    System.IO.Stream getStream = request.GetResponse().GetResponseStream();
                    byte[] resultByte = new byte[200];
                    getStream.Read(resultByte, 0, resultByte.Length);
                    Console.WriteLine(Encoding.UTF8.GetString(resultByte));
                  
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                Console.ReadLine();
            }
        }
    }
    

    For more information, please refer to the following articles:

    1.How to Create WCF REST Service for Mobile App

    I hope that will be helpful to you.

    Best Regards,

    Grady

    • Marked as answer by HanneSThEGreaT Wednesday, August 19, 2015 12:48 PM
    Tuesday, August 18, 2015 10:03 AM
    Moderator
  • Thank you so much for your wonderful reply. According to your advice, I have done this: Config file : <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <system.web> <compilation debug="true" targetFramework="4.5"> <assemblies> <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </assemblies> </compilation> <httpRuntime targetFramework="4.5" /> </system.web> <system.serviceModel> <bindings> <webHttpBinding> <binding name="webBingding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/> </binding> </webHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="Default"> <serviceMetadata httpGetUrl="mex" httpGetEnabled="true"/> <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="False"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="webHttpendBehavior"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> <services> <service name='Prosound_Service.DataService' behaviorConfiguration='Default'> <host> <baseAddresses> <add baseAddress="http://localhost/Test_Service"/> </baseAddresses> </host> <endpoint address="" binding="webHttpBinding" bindingConfiguration='webBingding' contract="Prosound_Service.IService1" behaviorConfiguration="webHttpendBehavior"> </endpoint> </service> </services> </system.serviceModel> <connectionStrings> <add name="Umbrella_ProsoundEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=htg\umbrella;initial catalog=Umbrella_Prosound;user id=0022;password=hannes123;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> </entityFramework> </configuration> Interface: <ServiceContract()> _ Public Interface IService1 Inherits IServiceProvider <OperationContract()> _ <WebInvoke(Method:="POST", UriTemplate:="postMostStr/{streamLength}", BodyStyle:=WebMessageBodyStyle.Bare)> _ Function SendEmail(EmailAddress As String) As Boolean End Interface Service: Imports Microsoft.VisualBasic Imports System Imports System.Collections.Generic Imports System.Data.Services Imports System.Data.Services.Common Imports System.Data.Services.Providers Imports System.Linq Imports System.ServiceModel.Web Imports System.Web #If DEBUG Then <System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults:=True)> _ <Prosound_Service.JSONPSupportBehavior> _ Public Class DataService Inherits DataService(Of Umbrella_ProsoundEntities) ' Implements IService1 #Else <Prosound_Service.JSONPSupportBehavior> _ Public Class DataService #End If Implements IServiceProvider, IService1 ' This method is called only once to initialize service-wide policies. Public Shared Sub InitializeService(ByVal config As DataServiceConfiguration) ' TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc. ' Examples: ' config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead) ' config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All) config.SetEntitySetAccessRule("*", EntitySetRights.All) config.SetServiceOperationAccessRule("*", ServiceOperationRights.All) config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3 config.SetServiceOperationAccessRule("SendEmail", ServiceOperationRights.All) #If DEBUG Then config.UseVerboseErrors = True #End If End Sub Public Function GetService(ByVal serviceType As Type) As Object Implements IServiceProvider.GetService If serviceType Is GetType(IDataServiceStreamProvider) Then ' Return the stream provider to the data service. Return New Prosound_Service.ImageStreamProvider() End If Return Nothing End Function <WebInvoke> _ Public Function SendEmail(emailAddress As String) As Boolean Implements IService1.SendEmail Return Extras.SendEmailNotification(0, 22, emailAddress, "test Email", "Test Email", 0) End Function End Class Now I get an Endpoint not found error
    Tuesday, August 18, 2015 10:42 AM
  • Hi HanneSThEGreaT,

    Sorry, here I forget a few notes:

    1.In my solution, I have two console applications and two class projects.

    One console application for host our WCF Service and in app.config file I configure my service.

    And we need to add the Contract class  project  reference and  Service class  project  reference

    in this application. One console application for test my service.

    2.In service class project we need add reference from contract class project.

    Next, you say you get an Endpoint not found error information. I suggest you can set your

    base address like below:

    Marking a port number in address, some times when the default port is occupied,

    we will not find the address

    <add baseAddress="http://LocalHost:7789/MySericeDemo"/>

    For more information, please refer to the following articles:

    1.Endpoint not found - WCF web service

    Best Regards,

    Grady

    Tuesday, August 18, 2015 11:55 AM
    Moderator