You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by cl...@apache.org on 2010/10/24 06:14:03 UTC

svn commit: r1026737 - in /qpid/trunk/qpid/wcf/samples/Channel/HelloWorld: ./ HelloWorld.cs HelloWorld.csproj

Author: cliffjansen
Date: Sun Oct 24 04:14:02 2010
New Revision: 1026737

URL: http://svn.apache.org/viewvc?rev=1026737&view=rev
Log:
hello world sample from QPID-2557.patch

Added:
    qpid/trunk/qpid/wcf/samples/Channel/HelloWorld/
    qpid/trunk/qpid/wcf/samples/Channel/HelloWorld/HelloWorld.cs
    qpid/trunk/qpid/wcf/samples/Channel/HelloWorld/HelloWorld.csproj

Added: qpid/trunk/qpid/wcf/samples/Channel/HelloWorld/HelloWorld.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/wcf/samples/Channel/HelloWorld/HelloWorld.cs?rev=1026737&view=auto
==============================================================================
--- qpid/trunk/qpid/wcf/samples/Channel/HelloWorld/HelloWorld.cs (added)
+++ qpid/trunk/qpid/wcf/samples/Channel/HelloWorld/HelloWorld.cs Sun Oct 24 04:14:02 2010
@@ -0,0 +1,118 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+/*
+ * A simple Hello world program that sends and receives a message
+ * to and from an AMQP broker.  The text content is sent as UTF8
+ * in "raw" form on the wire (so that it matches the C++ client 
+ * sample).
+ * 
+ * This program requires that the source queue exists and has
+ * an explicit or implicit binding to the target.  The following
+ * commands work in the default case:
+ * 
+ *   python qpid-config add queue my_topic_node
+ *   python qpid-config bind amq.topic my_topic_node "*"
+ *   
+ */
+
+namespace Apache.Qpid.Samples.Channel.HelloWorld
+{
+    using System;
+    using System.ServiceModel;
+    using System.ServiceModel.Channels;
+    using System.ServiceModel.Description;
+    using System.Text;
+    using System.Xml;
+    using Apache.Qpid.Channel;
+
+    public class HelloWorld
+    {  
+        static void Main(string[] args)
+        {
+            String broker = "localhost";
+            int port = 5672;
+            String target = "amq.topic";
+            String source = "my_topic_node";
+
+            if (args.Length > 0)
+            {
+                broker = args[0];
+            }
+
+            if (args.Length > 1)
+            {
+                port = int.Parse(args[1]);
+            }
+
+            if (args.Length > 2)
+            {
+                target = args[2];
+            }
+
+            if (args.Length > 3)
+            {
+                source = args[3];
+            }
+
+            AmqpBinaryBinding binding = new AmqpBinaryBinding();
+            binding.BrokerHost = broker;
+            binding.BrokerPort = port;
+
+            IChannelFactory<IInputChannel> receiverFactory = binding.BuildChannelFactory<IInputChannel>();
+            receiverFactory.Open();
+            IInputChannel receiver = receiverFactory.CreateChannel(new EndpointAddress("amqp:" + source));
+            receiver.Open();
+
+            IChannelFactory<IOutputChannel> senderFactory = binding.BuildChannelFactory<IOutputChannel>();
+            senderFactory.Open();
+            IOutputChannel sender = senderFactory.CreateChannel(new EndpointAddress("amqp:" + target));
+            sender.Open();
+
+            sender.Send(Message.CreateMessage(MessageVersion.None, "", new HelloWorldBinaryBodyWriter()));
+
+            Message message = receiver.Receive();
+            XmlDictionaryReader reader = message.GetReaderAtBodyContents();
+            while (!reader.HasValue)
+            {
+                reader.Read();
+            }
+
+            byte[] binaryContent = reader.ReadContentAsBase64();
+            string text = Encoding.UTF8.GetString(binaryContent);
+
+            Console.WriteLine(text);
+
+            senderFactory.Close();
+            receiverFactory.Close();
+        }
+    }
+
+    public class HelloWorldBinaryBodyWriter : BodyWriter
+    {
+        public HelloWorldBinaryBodyWriter() : base (true) {}
+
+        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
+        {
+            byte[] binaryContent = Encoding.UTF8.GetBytes("Hello world!");
+            writer.WriteStartElement("Binary");
+            writer.WriteBase64(binaryContent, 0, binaryContent.Length);
+        }
+    }
+}

Added: qpid/trunk/qpid/wcf/samples/Channel/HelloWorld/HelloWorld.csproj
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/wcf/samples/Channel/HelloWorld/HelloWorld.csproj?rev=1026737&view=auto
==============================================================================
--- qpid/trunk/qpid/wcf/samples/Channel/HelloWorld/HelloWorld.csproj (added)
+++ qpid/trunk/qpid/wcf/samples/Channel/HelloWorld/HelloWorld.csproj Sun Oct 24 04:14:02 2010
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.21022</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{CCB71C9F-D332-4FD9-9C98-4519BD6498C4}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>HelloWorld</RootNamespace>
+    <AssemblyName>HelloWorld</AssemblyName>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Apache.Qpid.Channel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=679e1f50b62dbace, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\src\Apache\Qpid\Channel\bin\Release\Apache.Qpid.Channel.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Runtime.Serialization">
+      <RequiredTargetFramework>3.0</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.ServiceModel">
+      <RequiredTargetFramework>3.0</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.XML" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="HelloWorld.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org