Monday, November 12, 2012

WCF Service Host without app.config (configuration by code) example

using System;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;


namespace wcf3
{
    class Program
    {
        static void Main(string[] args)
        {

            ServiceHost serviceHost = new ServiceHost(typeof(TestService), new Uri("http://localhost:80/Test3"));

            // Create Meta Behavior
            ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
            behavior.HttpGetEnabled = true;

            serviceHost.Description.Behaviors.Add(behavior);

            Binding mexBinding = MetadataExchangeBindings.CreateMexHttpBinding();

            serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "mex");

            WSHttpBinding httpBinding = new WSHttpBinding(SecurityMode.None);

            serviceHost.AddServiceEndpoint(typeof(ITestService), httpBinding, "rest");

            serviceHost.Open();
            Console.WriteLine("TestService is now running. at: " + serviceHost.BaseAddresses.First());
            Console.WriteLine("Press any key to stop it ...");
            Console.ReadKey();
            serviceHost.Close();
        }
    }

    [ServiceContract]
    public interface ITestService
    {
        [OperationContract]
        string Test(string input);
    }

    public class TestService : ITestService
    {

        public string Test(string input)
        {
            return input + DateTime.Now.ToString();
        }
    }



}

WCF Basics

1) Visual Stuido: WCF Service Projekt anlegen (=Server) :
Erzeugt ein .svc File, in dem der ServiceHost deklariert wird, der dann das eigentlcihe Service , die Klasse Service 1 im .svc.cs, die wiederum das Interface IService1 implementiert. GetData ist die Beispielmethode.0

1a) Klasse ServiceContract mit Methoden OperationCopntracts
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }

2a) CLient anlegen:  z.b. WinForm oder WPF oder CMD Line  Projekt - oder mitgeliefreten WcfTestClient.exe verwenden (im Projekt wird bei Debug Command Line Arguments  /client:"WcfTestClient.exe" hinzugefügt bei einer WCF Class LIbrary - zu finden in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE)
2b) Service Reference hinzufügen, Discover und OK drücken und ServiceReference1 wird erzeugt
2c) In einem Button Click einen Client erzeugen und auf dem GetData aufrufen:


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
            string s=client.GetData(10);
            MessageBox.Show("returns: " + s);
        }

weitere Info:
http://www.michis-blog.net/wp-content/uploads/2007/05/wcf-tutorial.pdf
http://www.codeproject.com/Articles/97204/Implementing-a-Basic-Hello-World-WCF-Service
https://weblogs.asp.net/ralfw/a-truely-simple-example-to-get-started-with-wcf


3) Error Handling

ServiceHost only supports class service types

maybe the interface was specified instead of the implementation in the .svc file

WCF Basics

1) Visual Stuido: WCF Service Projekt anlegen (=Server) :
Erzeugt ein .svc File, in dem der ServiceHost deklariert wird, der dann das eigentlcihe Service , die Klasse Service 1 im .svc.cs, die wiederum das Interface IService1 implementiert. GetData ist die Beispielmethode.0

1a) Klasse ServiceContract mit Methoden OperationCopntracts
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }

2a) CLient anlegen:  z.b. WinForm oder WPF oder CMD Line  Projekt - oder mitgeliefreten WcfTestClient.exe verwenden (im Projekt wird bei Debug Command Line Arguments  /client:"WcfTestClient.exe" hinzugefügt bei einer WCF Class LIbrary - zu finden in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE)
2b) Service Reference hinzufügen, Discover und OK drücken und ServiceReference1 wird erzeugt
2c) In einem Button Click einen Client erzeugen und auf dem GetData aufrufen:


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
            string s=client.GetData(10);
            MessageBox.Show("returns: " + s);
        }

weitere Info:
http://www.michis-blog.net/wp-content/uploads/2007/05/wcf-tutorial.pdf
http://www.codeproject.com/Articles/97204/Implementing-a-Basic-Hello-World-WCF-Service
https://weblogs.asp.net/ralfw/a-truely-simple-example-to-get-started-with-wcf


3) Error Handling

ServiceHost only supports class service types

maybe the interface was specified instead of the implementation in the .svc file

Friday, November 09, 2012

WPF Databinding: über DataContext

z.b.:

im Xaml:

IsEnabled="{Binding Source={StaticResource DataContextBridge}, Path=DataContext.Model.IsLocked}"

im CodeBehind:


        public void Initialize(ImportExportViewModel model, IUnityContainer unityContainer)
        {
            ((FrameworkElement)Resources["DataContextBridge"]).DataContext = DataContext;
DataContext = yourDatModel;
        }

Wednesday, November 07, 2012

oracle simple stored procedure


create or replace
PROCEDURE TESTHM AS
BEGIN
--set serveroutput on;
  --does not work: SELECT SESSIONTIMEZONE, CURRENT_DATE FROM DUAL;
  dbms_output.put_line ('TestHm');
  --does not work: ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
  dbms_output.put_line (CURRENT_DATE);
END TESTHM;

testen:
set serveroutput on;      
execute testhm;

mit Parameter:
create or replace

PROCEDURE TESTHM
(
     InTest   IN  VARCHAR2
)
IS
BEGIN
--set serveroutput on;
  dbms_output.put_line ('TestHm Begin');
  dbms_output.put_line (InTest);
END TESTHM;




set serveroutput on;  
execute testhm('Hallo');

Monday, November 05, 2012

oracle enterprisemanger urls

sind in C:\oracle\product\10.2.0\db_1\install\readme.txt