Null reference Exception, Endpoint

0

Witam serdecznie, ostatnio probuje pisac programy w visual stdio 2013 i srednio mi to wychodzi
Teraz robie zadanie ktore polega na realizowaniu usług dostępnych w różny sposób (poprzez różne
protokoły i punkty końcowe), przy czym częściowo będą one generowane na
podstawie plików konfiguracyjnych. Ponadto będą przesyłane w wywołaniach
złożone zestawy danych (definiowane poprzez kontrakty danych

Uzylem Console application jako server i WCF Libary jako kontrakt servera.
Wyskakuje mi blad null exception przy debugowaniu i nie wiem jak go naprawic, wydaje mi sie ze endpoint jest przypisany.
W zalaczniku podaje screen bledu.

Oto kod hosta

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Security;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Threading.Tasks;
using WcfServiceLibrary1;

namespace SerwerZad4
{
class Program
{
static void Main(string[] args)
{
Uri baseAddress1 = new Uri("http://localhost:3005/SerwerZad4");
ServiceHost mojHost = new ServiceHost(typeof(KalkulatorLZ));
try
{

            ServiceEndpoint endpoint1 = mojHost.Description.Endpoints.Find(new Uri("http://localhost:3005/SerwerZad4/KalkulatorLZ"));
            Console.WriteLine("\nService endpoint {0} contains the following:", endpoint1.Name);     // tu pojawia sie blad
            Console.WriteLine("Binding: {0}", endpoint1.Binding.ToString());
            Console.WriteLine("Contract: {0}", endpoint1.Contract.ToString());
            Console.WriteLine("ListenUri: {0}", endpoint1.ListenUri.ToString());
            Console.WriteLine("ListenUriMode: {0}",
            endpoint1.ListenUriMode.ToString());



            mojHost.Open();
            Console.WriteLine("Serwis 1 jest uruchomiony.");
            Console.WriteLine("Nacisnij <ENTER> aby zakonczyc.");
            Console.WriteLine();
            Console.ReadLine();
            mojHost.Close();





            ContractDescription cd = ContractDescription.GetContract(typeof(IKalkulatorLZ));
            Console.WriteLine("Displaying information for contract: {0}",
            cd.Name.ToString());
            string configName = cd.ConfigurationName;
            Console.WriteLine("\tConfiguration name: {0}", configName);
            Type contractType = cd.ContractType;
            Console.WriteLine("\tContract type: {0}", contractType.ToString());
            bool hasProtectionLevel = cd.HasProtectionLevel;
            if (hasProtectionLevel)
            {
                ProtectionLevel protectionLevel = cd.ProtectionLevel;
                Console.WriteLine("\tProtection Level: {0}",
                protectionLevel.ToString());
            }
            string name = cd.Name;
            Console.WriteLine("\tName: {0}", name);
            string namespc = cd.Namespace;
            Console.WriteLine("\tNamespace: {0}", namespc);
            OperationDescriptionCollection odc = cd.Operations;
            Console.WriteLine("\tDisplay Operations:");
            foreach (OperationDescription od in odc)
            {
                Console.WriteLine("\t\t" + od.Name);
            }
            SessionMode sm = cd.SessionMode;
            Console.WriteLine("\tSessionMode: {0}", sm.ToString());
        }
        catch (CommunicationException ce)
        {
            Console.WriteLine("Wystapil wyjatek: {0}", ce.Message);
            mojHost.Abort();
        }
    }
}

}

Rozumiem ze endpointa definiuje sie w app.config
Oto app config kontraktu

<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedruntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <system.servicemodel> <services> <service name="WcfServiceLibrary1.KalkulatorLZ" behaviorconfiguration="Wydajnosc"> <endpoint address="/KalkulatorLZ" binding="wsHttpBinding" contract="WcfServiceLibrary1.IKalkulatorLZ"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseaddresses> <add baseaddress="http://localhost:3005/SerwerZad4" /> </baseaddresses> </host> </service> </services> <behaviors> <servicebehaviors> <behavior name="Wydajnosc"> <servicethrottling maxconcurrentcalls="1" maxconcurrentsessions="1" maxconcurrentinstances="1" /> <servicemetadata httpgetenabled="true" httpgeturl="" /> </behavior> </servicebehaviors> </behaviors> </system.servicemodel> </configuration>

A tutaj podaje chociaz nie wiem czy ejst to potrzebne app config aplikacji hostujacej

<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedruntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> </configuration>
0

http://msdn.microsoft.com/pl-pl/library/ms554826(v=vs.110).aspx
"The first ServiceEndpoint of the specified address or null if none was found."

wydaje mi sie ze endpoint jest przypisany.

nie może Ci się wydawać musisz być pewien. Mnie się z kolei wydaje, że endpoint1 jest nullem.

1 użytkowników online, w tym zalogowanych: 0, gości: 1