tags:

views:

185

answers:

1
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="HTTPBaseAddress"
       value="http://localhost:8000/Derivatives/"/&gt;
    <add key="TCPBaseAddress"
       value="net.tcp://localhost:8010/Derivatives/"/>
  </appSettings>
  <system.diagnostics>
    <sources>
      <source
       name="System.ServiceModel.MessageLogging"
       switchValue="Verbose">
        <listeners>
          <add
         name="xml"
         type="System.Diagnostics.XmlWriterTraceListener"
         initializeData="c:\logs\message.log" />
        </listeners>
      </source>
    </sources>
    <trace autoflush="true" />
  </system.diagnostics>

  <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true"
          maxMessagesToLog="300"
          logMessagesAtServiceLevel="false"
          logMalformedMessages="true"
          logMessagesAtTransportLevel="true" />
    </diagnostics>

    <services>
      <service type=
"DerivativesCalculator.DerivativesCalculatorServiceType,DerivativesCalculatorService"
 behaviorConfiguration="DerivativesCalculatorService">
        <endpoint
        address="Calculator"
        binding="wsHttpBinding"
        contract=
"DerivativesCalculator.IDerivativesCalculator,DerivativesCalculatorService"
       />
      </service>
    </services>
    <behaviors>
      <behavior name="DerivativesCalculatorService">
        <serviceSecurityAudit auditLogLocation="Application" messageAuthenticationAuditLevel="SuccessOrFailure" serviceAuthorizationAuditLevel="SuccessOrFailure"/>
      </behavior>
    </behaviors>
  </system.serviceModel>
</configuration>

This App.config is generating the following Exception:

Unrecognized attribute 'type'. Note that attribute names are case-sensitive.

My Source code is as follows:

using System;
using System.Collections.Generic;
using System.Text;

namespace DerivativesCalculator
{
    public class Calculator
    {
        public decimal CalculateDerivative(
          string[] symbols,
          decimal[] parameters,
          string[] functions)
        {
            return (decimal)(System.DateTime.Now.Millisecond);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

using DerivativesCalculatorService;
using DerivativesCalculator;

namespace DerivativesCalculator
{
    public class DerivativesCalculatorServiceType : IDerivativesCalculator
    {
        decimal IDerivativesCalculator.CalculateDerivative(
        string[] symbols,
        decimal[] parameters,
        string[] functions)
        {
            return new Calculator().CalculateDerivative(
                symbols, parameters, functions);

        }

        void IDerivativesCalculator.DoNothing()
        {
            return;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;

namespace DerivativesCalculatorService
{
    [ServiceContract]
    public interface IDerivativesCalculator
    {
        [OperationContract]
        decimal CalculateDerivative(
            string[] symbols,
            decimal[] parameters,
            string[] functions);

        void DoNothing();
    }
}


using System;
using System.Collections.Generic;
using System.Configuration;
using System.ServiceModel;
using System.Text;

namespace DerivativesCalculator
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Type serviceType = typeof(DerivativesCalculatorServiceType);

            string httpBaseAddress = ConfigurationManager.AppSettings["HTTPBaseAddress"];
            string tcpBaseAddress = ConfigurationManager.AppSettings["TCPBaseAddress"];

            Uri httpBaseAddressUri = new Uri(httpBaseAddress);
            Uri tcpBaseAddressUri = new Uri(tcpBaseAddress);
            Uri[] baseAdresses = new Uri[] {
                httpBaseAddressUri,
                tcpBaseAddressUri};

            using (ServiceHost host = new ServiceHost(
                serviceType,
                baseAdresses))
            {
                host.Open();

                Console.WriteLine("The derivatives calculator service is available.");
                Console.ReadKey();

                host.Close();
            }
        }
    }
}

How to solve this?

+3  A: 

I believe that this line of your configuration file is incorrect:

<service
type="DerivativesCalculator.DerivativesCalculatorServiceType,DerivativesCalculatorService"
behaviorConfiguration="DerivativesCalculatorService">

I think instead the type="" should be name="".

<service
name="DerivativesCalculator.DerivativesCalculatorServiceType,DerivativesCalculatorService"
behaviorConfiguration="DerivativesCalculatorService">

Stuart Thompson
Stuart: I think you're right; also, the name="...." should only contain the name of the service class - **NOT** the assembly after the comma, too!
marc_s
I have made the suggested change. But new Exception is showing up. :::::Unrecognized element 'behavior'::::::.
JMSA
I'm really not sure what would cause the behavior element to be unrecognized. The only idea I can come up with is that perhaps an error was made when changing the type attribute to name. Is it possible there is a mismatched " / or > symbol somewhere in the file? As long as <behavior> is under <behaviors> in <system.serviceModel> the file should be legal.
Stuart Thompson