gpt4 book ai didi

c# - WCF 异常 : InvalidOperationException was unhandled

转载 作者:行者123 更新时间:2023-11-30 15:48:50 29 4
gpt4 key购买 nike

由于我正在考虑使用 WCF,所以我认为最好只是按照一个简单的教程来尝试一下。

3 小时后,我只有一个异常(exception)要显示。它不会消失。

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

有没有人知道如何调试它?这种黑框错误让我非常反感。

完全异常(exception):

Service 'WCFtest.TestService' has zero application (non-infrastructure) endpoints. 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

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

我的程序.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
}
}

我的应用程序配置

<?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 的新手......

关于c# - WCF 异常 : InvalidOperationException was unhandled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2228781/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com