简体   繁体   English

WCF异常:未处理InvalidOperationException

[英]WCF Exception: InvalidOperationException was unhandled

Since I'm contemplating to use WCF I thought it would be best to just follow a simple tutorial to get my feet wet. 由于我正在考虑使用WCF,我认为最好只是按照一个简单的教程来弄湿我的脚。

3 hours later, I've only got one exception to show for. 3个小时后,我只有一个例外。 It won't go away. 它不会消失。

I ruled out the app.config not being loaded. 我排除了app.config没有被加载。 If I change: wsHttpBinding in the config to JHGHJGH it gives an error when running. 如果我将配置中的wsHttpBinding更改为JHGHJGH,则在运行时会出错。 However when I change the name of the contract interface, no errors are given (except the same one I'm facing for the last 3 hours) 但是当我更改合同界面的名称时,没有给出任何错误(除了我在过去3小时内遇到的同一个错误)

Does anyone have an idea how to debug this? 有谁知道如何调试这个? This kind of blackbox error stuff is very off-putting for me. 这种黑盒子错误的东西对我来说非常不利。

full exception: 完全例外:

Service 'WCFtest.TestService' has zero application (non-infrastructure) endpoints. 服务'WCFtest.TestService'具有零应用程序(非基础结构)端点。 This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element 这可能是因为没有为您的应用程序找到配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为没有在服务元素中定义端点

(Don't you love these errors which indicate any of 16 possible things which might be wrong) (难道你不喜欢这些错误,这些错误表明16种可能错误的东西)

my program.cs 我的program.cs

ServiceHost host;
Type serviceType = typeof(TestService);
host = new ServiceHost(serviceType);
host.Open();  //<---- exception is thrown here
Console.ReadLine();

my test 'wcf service' 我的测试'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
    }
}

my app.config 我的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>

It's not a case thing, is it? 这不是一个案例,是吗? Your web config says; 你的网络配置说;

WCFtest.testservice

but your code says 但你的代码说

WCFtest.TestService 

So I suspect the difference in case may do something; 所以我怀疑案件的不同可能会有所作为; usually, C# types are case-sensitive. 通常,C#类型区分大小写。 I'm new to WCF, though... 我是WCF的新手,不过......

The "name" attribute of the element in the app.config is case sensitive. app.config中元素的“name”属性区分大小写。

Instead of "WCFTest.testservice", you need to specify "WCFtest.TestService" like so: 而不是“WCFTest.testservice”,您需要指定“WCFtest.TestService”,如下所示:

<service name="WCFtest.TestService" behaviorConfiguration="testservicebehaviour">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未处理InvalidOperationException - InvalidOperationException was unhandled WCF 用户代码未处理的异常 - WCF unhandled exception by user code System.dll中发生了类型为&#39;System.InvalidOperationException&#39;的未处理异常 - An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll WebDriver.dll中发生了未处理的“System.InvalidOperationException”类型异常 - An unhandled exception of type 'System.InvalidOperationException' occurred in WebDriver.dll mscorlib.dll中发生了类型为&#39;System.InvalidOperationException&#39;的未处理异常 - An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll System.InvalidOperationException的未处理异常打破了我的MVC应用程序? - An unhandled exception of System.InvalidOperationException breaks my MVC App? 发生未处理的异常C#的system.data.dll中发生了类型&#39;system.invalidoperationexception&#39;的未处理异常 - An unhandled exception occured an unhandled exception of type 'system.invalidoperationexception' occurred in system.data.dll in c# 未处理的异常会使WCF服务崩溃吗? - unhandled exception will make WCF service crash? 该进程由于未处理的异常而终止-WCF服务 - The process was terminated due to an unhandled exception - WCF service xamarin PCL使用WCF:Android中未处理的异常 - xamarin PCL consume WCF: unhandled exception in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM