<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="HTTPBaseAddress"
value="http://localhost:8000/Derivatives/"/>
<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>
此App.config正在生成以下异常:
Unrecognized attribute 'type'. Note that attribute names are case-sensitive.
我的源代码如下:
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();
}
}
}
}
如何解决这个问题?
答案 0 :(得分:3)
我认为配置文件的这一行不正确:
<service
type="DerivativesCalculator.DerivativesCalculatorServiceType,DerivativesCalculatorService"
behaviorConfiguration="DerivativesCalculatorService">
我认为type =“”应该是name =“”。
<service
name="DerivativesCalculator.DerivativesCalculatorServiceType,DerivativesCalculatorService"
behaviorConfiguration="DerivativesCalculatorService">