【问题标题】:Client endpoint configuration '*' was not found in 1 Endpoints, WCF, Mono在 1 个端点、WCF、Mono 中找不到客户端端点配置“*”
【发布时间】:2012-06-07 20:33:13
【问题描述】:

伙计们,

我正在尝试使用 Mono 从我的 Ubuntu 主机访问托管在虚拟机 (Windows 7) 上的 Web 服务。

我可以导入 wdsl 文件并生成服务参考。我从另一个正确访问 Web 服务的工作客户端复制了 App.config。

当我尝试使用 使用系统;

namespace MonoTest
{
class MainClass
{
    public static void Main (string[] args)
    {
        Console.WriteLine ("Hello World!");
        TestServer.Service1Client client = new TestServer.Service1Client("Test");
        Console.WriteLine(client.GetData(12));
        Console.ReadLine();
    }
}
}

我得到一个错误:

System.InvalidOperationException: Client endpoint configuration 'Test' was not found in 1 endpoints.
  at System.ServiceModel.ChannelFactory.ApplyConfiguration (System.String endpointConfig) [0x00000] in <filename unknown>:0 
  at System.ServiceModel.ChannelFactory.InitializeEndpoint (System.String endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in <filename unknown>:0 
  at System.ServiceModel.ChannelFactory`1[MonoTest.TestServer.IService1]..ctor (System.String endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in <filename unknown>:0 
  at System.ServiceModel.ClientBase`1[MonoTest.TestServer.IService1].Initialize (System.ServiceModel.InstanceContext instance, System.String endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in <filename unknown>:0 
  at System.ServiceModel.ClientBase`1[MonoTest.TestServer.IService1]..ctor (System.ServiceModel.InstanceContext instance, System.String endpointConfigurationName) [0x00000] in <filename unknown>:0 
  at System.ServiceModel.ClientBase`1[MonoTest.TestServer.IService1]..ctor (System.String endpointConfigurationName) [0x00000] in <filename unknown>:0 
  at MonoTest.TestServer.Service1Client..ctor (System.String endpointConfigurationName) [0x00000] in <filename unknown>:0 
  at MonoTest.MainClass.Main (System.String[] args) [0x0000a] in /home/***/WebserviceTest/MonoTest/MonoTest/Main.cs:11 

我的 App.config 文件如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IService1" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint name="Test"
                address="http://192.168.178.34:8732/Design_Time_Addresses/TestServer/Service1/"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
                contract="ServiceReference1.IService1" >
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

有人用 Linux 做这个吗?

【问题讨论】:

    标签: c# linux wcf mono wcf-endpoint


    【解决方案1】:

    Mono 的 WSDL 导入工具尚不支持自动配置生成,您需要在 app.config 中手动配置端点。

    您在此处看到的错误意味着 WCF 找不到端点配置部分。

    问题的详细技术原因

    你得到这个是因为 Visual Studio 和 Mono 有不同的、不兼容的方式来引用配置部分。

    在 Visual Studio 中添加服务引用时,它会自动创建并更新您的 app.config 中的相应条目。生成的&lt;endpoint ... contract="contract name"&gt; 中的“合约名称”不一定是生成的Reference.cs 中数据合约类的完全限定名称。

    相反,Visual Studio 发出

        [ServiceContractAttribute(ConfigurationName="contract name")]
        public interface YourContract {
                ....
        }
    

    ConfigurationName&lt;endpoint ... contract="..."&gt; 元素中的相同,这就是 WCF 查找端点配置的方式。

    在 Mono 中,由于我们还不支持配置文件生成,我们发出

        [ServiceContractAttribute]
        public interface YourContract {
                ....
        }
    

    没有ConfigurationName 参数,默认是该接口的完全限定名称。

    如何解决您的问题

    要使其正常工作,您需要编辑 app.config 文件并在 &lt;endpoint ... contract="..."&gt; 元素中使用服务合同接口的完全限定名称。

    在您的情况下,将 contract="ServiceReference1.IService1" 更改为 contract="TestServer.IService1" 应该可以。

    否则,查看生成的Reference.cs,搜索带有[ServiceContractAttribute] 的接口以及它所在的C# 命名空间。

    【讨论】:

      【解决方案2】:

      Mono WCF 是 dotnet WCF 的部分实现,因此不支持少数功能和绑定:

      还有一篇文章说

      没有计划支持的组件

      WSHttpBinding 及其依赖项 交易流 可靠会话

      请看: http://www.mono-project.com/WCF_Development

      【讨论】:

      • 谢谢,这个问题实际上已经很老了,我不再寻找解决方案了。但是感谢您的帮助!
      猜你喜欢
      • 2012-02-07
      • 2014-05-12
      • 1970-01-01
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      • 2012-02-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多