簡體   English   中英

WCF異常:未處理InvalidOperationException

[英]WCF Exception: InvalidOperationException was unhandled

由於我正在考慮使用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>

這不是一個案例,是嗎? 你的網絡配置說;

WCFtest.testservice

但你的代碼說

WCFtest.TestService 

所以我懷疑案件的不同可能會有所作為; 通常,C#類型區分大小寫。 我是WCF的新手,不過......

app.config中元素的“name”屬性區分大小寫。

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM