Connection to on premises servicebus instance.

Oct 2, 2014 at 11:29 AM
Hi,

I am trying to connect to an on premises windows servicebus 1.1 instance. I have installed the AutoGeneratedCA.cer on the client and created a namespace (with windows user authentication) and a queue on the server.

Here is my test program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Amqp;
using Amqp.Types;
using System.Net;

namespace AmqpTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string username = "<MyUsername>"; //Domain username
            string password = "<MyPassword>"; //Domain Password
            string hostname = "<MySericeBusURL>"; //on premises service bus instance
            string ns = "<MyNamespace>"; //service bus namespace
            string queue = "test"; //the queue to which we are talking to

            Address address = new Address(string.Format("amqps://{0}:{1}@{2}:5671/{3}/", WebUtility.UrlEncode(username), WebUtility.UrlEncode(password), hostname, ns));
            Connection connection = new Connection(address);
            Session session = new Session(connection);

            SenderLink sender = new SenderLink(session, "send-link", queue);
            ReceiverLink receiver = new ReceiverLink(session, "reviever-link", queue);


            bool execute = true;
            while (execute)
            {
                try
                {
                Console.WriteLine();
                Console.Write("Press 'T' to send a timestamp, 'C' to receive messages or 'Q' to exit: ");
                switch (Console.ReadKey().Key)
                {
                    case ConsoleKey.T:
                        Console.WriteLine();
                        Message message = new Message();
                        message.ApplicationProperties = new Amqp.Framing.ApplicationProperties();
                        message.ApplicationProperties["From"] = "TestDevice";
                        message.ApplicationProperties["Event-Timestamp"] = DateTime.UtcNow;
                        message.ApplicationProperties["Send-Timestamp"] = DateTime.UtcNow;
                        sender.Send(message, null, null);
                        Console.WriteLine("sent a timestamp");

                        break;

                    case ConsoleKey.C:
                        Console.WriteLine();
                        Console.WriteLine("Checking for messages.");
                        for (int i = 0; i < 200; ++i)
                        {
                            if (i % 50 == 0) receiver.SetCredit(50);
                            Message rMessage = receiver.Receive();
                            if (rMessage != null)
                            {
                                Console.WriteLine(string.Format("received from: {0} a tip at {1}", rMessage.ApplicationProperties["From"], rMessage.ApplicationProperties["Event-Timestamp"]));
                                receiver.Accept(rMessage);
                            }
                            else
                            {
                                Console.WriteLine("No Messages available.");
                                break;
                            }
                        }
                        break;

                    case ConsoleKey.Q:
                        Console.WriteLine();
                        Console.WriteLine("exiting application.");
                        execute = false;
                        break;

                    default:
                        Console.WriteLine("Unexpected keypress");
                        break;
                }
                }
                catch (Exception e)
                {

                    Console.WriteLine(e.ToString());
                }

            }

            sender.Close();
            receiver.Close();
            session.Close();
            connection.Close();
            


            
        }
    }
}
however the amqp library throws an exception when I try to send or receive messages, saying:
Press 'T' to send a timestamp, 'C' to receive messages or 'Q' to exit: t
Amqp.AmqpException: Operation 'Send' is not valid under state: End.
   at Amqp.Link.ThrowIfDetaching(String operation) in c:\Users\Robin\Documents\V
isual Studio 2013\Projects\AmqpTest\amqpnetlite\src\Link.cs:line 198
   at Amqp.SenderLink.Send(Message message, OutcomeCallback callback, Object sta
te) in c:\Users\Robin\Documents\Visual Studio 2013\Projects\AmqpTest\amqpnetlite
\src\SenderLink.cs:line 73
   at AmqpTest.Program.Main(String[] args) in c:\Users\Robin\Documents\Visual St
udio 2013\Projects\AmqpTest\Program.cs:line 46
Does anyone know why this could be happening and how I can correct it?

Many Thanks,

Robin.
Editor
Oct 2, 2014 at 11:31 AM
Hi Robin,
can you enable Trace to see the AMQP messages exchanged between your cliend and SB ?

Thanks,
Paolo.
Oct 2, 2014 at 11:34 AM
Hi Paolo,

Thanks for the very quick repy! How do I enable trace?
Editor
Oct 2, 2014 at 11:37 AM
Hi Robin,

you can find more information in documentation here :

https://amqpnetlite.codeplex.com/wikipage?title=Tracing&referringTitle=Documentation

Paolo.
Oct 2, 2014 at 11:40 AM
Found it!
[11:31.909] SEND AMQP 3 1 0 0
[11:31.927] SEND sasl-init(mechanism:PLAIN,initial-response:0061646D696E6973747261746F720057656C636F6D65313233,hostname:servicebus.<mydomain>.local)
[11:31.929] RECV AMQP 3 1 0 0
[11:31.936] RECV sasl-mechanisms(sasl-server-mechanisms:[PLAIN,EXTERNAL])
[11:31.939] RECV sasl-outcome(code:0,additional-data:57656C636F6D6521)
[11:31.943] SEND AMQP 0 1.0.0
[11:31.945] SEND (ch=0) open(container-id:3c38d2a3-64b0-45f7-86f8-26a684e69d4b,host-name:servicebus.<mydomain>.local,max-frame-size:16384,channel-max:3)
[11:31.948] SEND (ch=0) begin(next-outgoing-id:4294967293,incoming-window:2048,outgoing-window:2048,handle-max:7)
[11:31.950] RECV AMQP 0 1 0 0
[11:31.953] RECV (ch=0) open(container-id:0b7565f1ecd5489d9ecce2d795592da0_GServiceBus,max-frame-size:16384,channel-max:3,idle-time-out:240000)
[11:31.953] SEND (ch=0) attach(name:send-link,handle:0,role:False,source:source(),target:target(address:test),initial-delivery-count:0)
[11:31.955] RECV (ch=0) begin(remote-channel:0,next-outgoing-id:1,incoming-window:2048,outgoing-window:2048,handle-max:7)
[11:31.956] SEND (ch=0) attach(name:reviever-link,handle:1,role:True,source:source(address:test),target:target())
[11:31.960] RECV (ch=0) attach(name:send-link,handle:0,role:True,source:source(),initial-delivery-count:0)
[11:31.964] RECV (ch=0) detach(handle:0,closed:True,error:error(condition:amqp:internal-error,description:The server was unable to process the request; please retry the operation. If the problem persists, please contact your Service Bus administrator and provide the tracking id..TrackingId:0b7565f1ecd5489d9ecce2d795592da0_GServiceBus,TimeStamp:02/10/2014 10:36:12))
[11:31.967] SEND (ch=0) detach(handle:0,closed:True)
[11:31.969] RECV (ch=0) attach(name:reviever-link,handle:1,role:False,target:target())
[11:31.972] RECV (ch=0) detach(handle:1,closed:True,error:error(condition:amqp:internal-error,description:The server was unable to process the request; please retry the operation. If the problem persists, please contact your Service Bus administrator and provide the tracking id..TrackingId:0b7565f1ecd5489d9ecce2d795592da0_GServiceBus,TimeStamp:02/10/2014 10:36:12))
[11:31.974] SEND (ch=0) detach(handle:1,closed:True)
A first chance exception of type 'Amqp.AmqpException' occurred in Amqp.Net.dll
Oct 2, 2014 at 11:52 AM
I have kind of solved the problem:

Because the namespace comes after the port, the library cant process it! I added the namespace to the front of the queue (e.g. string queue = "/<myns>/test2";) and it now works correctly!
Coordinator
Oct 2, 2014 at 7:00 PM
Nice work with solving the issue!

Similar to the Qpid Java client, this client does not use the path in the address Uri to make a full entity name, you will have to do that when creating the link. (more information can be found here)

However, It sounds like a good thing to do to include Address.Path in the link address. The current behavior is a little bit confusing and not-easy to trouble shoot.