title: Microsoft ServiceBus - The argument entityName is null or empty
body: <p>I am using Servicebus as a link between a web-application and BizTalk.
  In the web-application i earlier had the whole endpoint defined in the web.config but the endpoints has to be dynamic so i tried to set the endpoint by code.</p>
  
  <p>After the change i only get an exception when i try to send a message to the queue. (ArgumentException - The argument entityName is null or empty)</p>
  
  <p>Here is the code sending the message to the queue:</p>
  
  <pre><code>string queuename = Company.GetQueueName(O.companyId);
  var factory = new ChannelFactory&lt;IOrder&gt;("requestQueueClientEndpoint", new EndpointAddress(ServiceBusEnvironment.CreateServiceUri("sb", queuename, string.Empty)));
  var OrdRspChannel = factory.CreateChannel();
  
  OrdRspChannel.Order(O);
  </code></pre>
  
  <p>And here is the configuration:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
  &lt;behaviors&gt;
    &lt;endpointBehaviors&gt;
      &lt;behavior name="securityBehavior"&gt;
        &lt;TransportClientEndpointBehavior&gt;
          &lt;tokenProvider&gt;
            &lt;sharedSecret issuerName="owner" issuerSecret="SECRET REMOVED" /&gt;
            &lt;serviceCertificate&gt;
              &lt;authentication revocationMode="NoCheck"/&gt;
            &lt;/serviceCertificate&gt;
          &lt;/tokenProvider&gt;
        &lt;/TransportClientEndpointBehavior&gt;
      &lt;/behavior&gt;
    &lt;/endpointBehaviors&gt;
  &lt;/behaviors&gt;
  
  &lt;bindings&gt;
    &lt;netMessagingBinding&gt;
      &lt;binding name="netMessagingBinding" sendTimeout="00:10:00" receiveTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00" sessionIdleTimeout="00:10:00" prefetchCount="-1"&gt;
        &lt;transportSettings batchFlushInterval="00:00:01" /&gt;
      &lt;/binding&gt;
    &lt;/netMessagingBinding&gt;
  &lt;/bindings&gt;
  
  &lt;client&gt;
    &lt;!-- Invoke BizTalk via Service Bus Queue --&gt;
    &lt;endpoint address="ADDRESS REMOVED" behaviorConfiguration="securityBehavior" binding="netMessagingBinding" bindingConfiguration="netMessagingBinding" contract="Procurement_MVC3.IOrder" name="requestQueueClientEndpoint" /&gt;
  &lt;/client&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>Here is the StackTrace:</p>
  
  <pre><code>{System.ArgumentException: The argument entityName is null or empty.
  Parameter name: entityName
  
  Server stack trace: 
     at Microsoft.ServiceBus.Messaging.MessagingFactory.CheckValidEntityName(String entityName, Int32 maxEntityNameLength, Boolean allowSeparator, String paramName)
     at Microsoft.ServiceBus.Messaging.MessagingFactory.&lt;&gt;c__DisplayClass1d.&lt;BeginCreateMessageSender&gt;b__1b(AsyncCallback c, Object s)
     at Microsoft.ServiceBus.Messaging.OpenOnceManager.OpenOnceManagerAsyncResult`1.BeginOpenCompleted(IAsyncResult result)
     at Microsoft.ServiceBus.Messaging.OpenOnceManager.OpenOnceManagerAsyncResult`1.BeginOpen()
     at Microsoft.ServiceBus.Messaging.OpenOnceManager.OpenOnceManagerAsyncResult`1..ctor(OpenOnceManager openOnceManager, TimeSpan openTimeout, AsyncCallback callback, Object state, Func`3 beginOperation, EndOperation`1 endOperation)
     at Microsoft.ServiceBus.Messaging.OpenOnceManager.Begin[T](AsyncCallback callback, Object state, Func`3 beginOperation, Func`2 endOperation)
     at Microsoft.ServiceBus.Messaging.MessagingFactory.BeginCreateMessageSender(String entityPath, TimeSpan timeout, AsyncCallback callback, Object state)
     at Microsoft.ServiceBus.Messaging.Channels.ServiceBusOutputChannel.OpenMessagingFactoryAndMessageSenderAsyncResult.CreateFactoryComplete(IAsyncResult result)
     at Microsoft.ServiceBus.Messaging.Channels.ServiceBusOutputChannel.OpenMessagingFactoryAndMessageSenderAsyncResult..ctor(ServiceBusOutputChannel outputChannel, TimeSpan timeout, AsyncCallback callback, Object state)
     at Microsoft.ServiceBus.Messaging.Channels.ServiceBusOutputChannel.OnOpen(TimeSpan timeout)
     at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
     at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
     at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
     at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
     at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
     at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
     at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
  
  Exception rethrown at [0]: 
     at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
     at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
     at Procurement_MVC3.IOrder.Order(Order Order)
     at Procurement_MVC3.Controllers.HomeController.ViewOrder(String id, Nullable`1 date, Nullable`1 confirmqty, String orderrowid, String supplierorderId, Boolean confirm) in c:\Projects2\trunk\Procurement_MVC3\Procurement_MVC3\Controllers\HomeController.cs:line 229}
  </code></pre>
  
  <p>I have searched both Google and StackOverflow for similar scenarios but found nothing.
  I also have to update a production-environment with this code and this is the last piece of the puzzle so it's starting to drag on.</p>