由于我正在考虑使用WCF,我认为最好只是按照一个简单的教程来弄湿我的脚。
3小时后,我只有一个例外。它不会消失。
我排除了app.config没有被加载。 如果我将配置中的wsHttpBinding更改为JHGHJGH,则在运行时会出错。 但是,当我更改合同界面的名称时,没有给出任何错误(除了我在过去3小时内遇到的同一个错误)
有谁知道如何调试这个? 这种黑盒子错误的东西对我来说非常不利。
完全例外:
服务'WCFtest.TestService'为零 应用程序(非基础架构) 端点。这可能是因为没有 找到了您的配置文件 申请,或因为没有服务 与服务名称匹配的元素 可以在配置中找到 文件,或因为没有端点 在服务元素中定义
(难道你不喜欢这些错误,这些错误表明16种可能的错误中的任何一种可能是错误的)
我的program.cs
ServiceHost host;
Type serviceType = typeof(TestService);
host = new ServiceHost(serviceType);
host.Open(); //<---- exception is thrown here
Console.ReadLine();
我的测试'wcf服务'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace WCFtest
{
[ServiceContract]
public interface ITest
{
[OperationContract]
double Add(double n1, double n2);
[OperationContract]
double Subtract(double n1, double n2);
[OperationContract]
double Multiply(double n1, double n2);
[OperationContract]
double Divide(double n1, double n2);
}
public class TestService : ITest
{
public double Add(double n1, double n2)
{
double result = n1 + n2;
return result;
}
etc... some methods are removed for brevity
}
}
我的app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<services>
<service name="WCFtest.testservice"
behaviorConfiguration="testservicebehaviour">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/test"/>
</baseAddresses>
</host>
<endpoint address=""
binding="wsHttpBinding"
contract="WCFtest.ITest" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="testservicebehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
答案 0 :(得分:3)
这不是一个案例,是吗?您的网络配置说;
WCFtest.testservice
但你的代码说
WCFtest.TestService
所以我怀疑案件的不同可能会有所作为;通常,C#类型区分大小写。我是WCF的新手,但是......
答案 1 :(得分:1)
app.config中元素的“name”属性区分大小写。
而不是“WCFTest.testservice”,你需要像这样指定“WCFtest.TestService”:
<service name="WCFtest.TestService" behaviorConfiguration="testservicebehaviour">