客户端终结点配置'*'在1个终结点中未找到,WCF,Mono。

6

大家好,

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

我可以导入wdsl文件并生成服务引用。我从另一个成功访问WebService的客户端中复制了App.config文件。

当我尝试使用以下命令连接到WebService时:

using System;

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上成功使用过这个吗?
2个回答

9

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

您看到的错误意味着WCF无法找到端点配置部分。

问题的详细技术原因

这是由于Visual Studio和Mono引用配置部分的方式不同且不兼容。

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

相反,Visual Studio发出的是

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

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

在Mono中,由于我们尚未支持配置文件生成,因此我们会发出

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

没有给出 ConfigurationName 参数的情况下,其默认值为该接口的完全限定名称。 如何解决问题 要使其正常工作,您需要编辑 app.config 文件,并在<endpoint ... contract="...">元素中使用您的服务合同接口的完全限定名称。
在您的情况下,将 contract="ServiceReference1.IService1"更改为 contract="TestServer.IService1"即可。
否则,请查看生成的 Reference.cs ,搜索带有 [ServiceContractAttribute] 且C#命名空间的接口。

0

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

还有一篇文章提到:

没有计划支持的组件

WSHttpBinding及其依赖项 TransactionFlow ReliableSession

请参见: http://www.mono-project.com/WCF_Development


谢谢,问题实际上已经很久了,我不再寻求解决方案。但还是感谢你的帮助! - Sebastian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接