Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF异常:未处理InvalidOperationException_C#_.net_Wcf_Exception - Fatal编程技术网

C# WCF异常:未处理InvalidOperationException

C# WCF异常:未处理InvalidOperationException,c#,.net,wcf,exception,C#,.net,Wcf,Exception,因为我正在考虑使用WCF,所以我认为最好只是按照一个简单的教程让我的脚湿透 3个小时后,我只有一个例外。它不会消失 我排除了app.config没有被加载的可能性。 如果我将配置中的:wsHttpBinding更改为JHGHJGH,则在运行时会出现错误。 但是,当我更改合同接口的名称时,没有给出任何错误(除了我在过去3小时内遇到的同一个错误) 有人知道如何调试这个吗? 这种黑匣子错误的东西让我很反感 完全例外: 服务“WCFtest.TestService”的值为零 应用程序(非基础设施) 端点

因为我正在考虑使用WCF,所以我认为最好只是按照一个简单的教程让我的脚湿透

3个小时后,我只有一个例外。它不会消失

我排除了app.config没有被加载的可能性。 如果我将配置中的:wsHttpBinding更改为JHGHJGH,则在运行时会出现错误。 但是,当我更改合同接口的名称时,没有给出任何错误(除了我在过去3小时内遇到的同一个错误)

有人知道如何调试这个吗? 这种黑匣子错误的东西让我很反感

完全例外:

服务“WCFtest.TestService”的值为零 应用程序(非基础设施) 端点。这可能是因为没有 已找到您的配置文件 应用程序,或者因为没有服务 与服务名称匹配的元素 可以在配置中找到 文件,或者因为没有端点 在服务元素中定义

(难道你不喜欢这些错误,它们表明了16种可能错误的事情中的任何一种)

我的程序.cs

ServiceHost host;
Type serviceType = typeof(TestService);
host = new ServiceHost(serviceType);
host.Open();  //<---- exception is thrown here
Console.ReadLine();
我的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>

这不是一个案例,是吗?你的网页配置显示

WCFtest.testservice
但是你的代码说

WCFtest.TestService 
因此,我怀疑案例中的差异可能会起到一些作用;通常,C#类型区分大小写。我是WCF新手,不过…

app.config中元素的“name”属性区分大小写

您需要指定“WCFTest.testservice”而不是“WCFTest.testservice”,如下所示:



捕捉得好。我以为servicename实际上是你给它起的任何名字。但您是说它必须与实现服务的类相匹配。谢谢一个人怎么能在这件事上花上3个小时,而别人却在几分钟内发现了它(这在每个人身上都会发生;)。这里有一个解释——“配置文件中指定的服务名称属性用作相应ExchangeService.svc的查找键。它告诉宿主环境此配置所属的服务。”[来源:我对整个WPF体验有点害怕。表面上,它只是在源代码中添加了一些属性。但是配置,以及来回发送的东西(我嗅到了)复杂得令人难以置信。与其他技术(例如PHP)进行互操作是我不敢碰的事情。现在不要放弃它。这确实是在.net中进行进程间通信的唯一方法。来回发送的东西实际上是SOAP,PHP可以与之互操作,而且您还可以使用更轻、更安全的SOAP更友好的休息支持。一次咬一口,很快你就会爱上它的力量和灵活性。:)
WCFtest.TestService 
<service name="WCFtest.TestService" behaviorConfiguration="testservicebehaviour">