Seb*_*ian 6 c# linux mono wcf wcf-endpoint
嘿伙计们,
我正在尝试使用Mono从我的Ubuntu主机访问托管在虚拟机(Windows 7)上的Web服务.
我可以导入wdsl文件并生成服务引用.我从正确访问webservice的其他工作客户端复制了App.config.
当我尝试使用System连接到webservice时;
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
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
Run Code Online (Sandbox Code Playgroud)
我的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>
Run Code Online (Sandbox Code Playgroud)
有没有人使用Linux工作?
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 {
....
}
Run Code Online (Sandbox Code Playgroud)
在ConfigurationName相同的<endpoint ... contract="...">元素,这是WCF如何找到端点配置.
在Mono,由于我们还不支持配置文件生成,我们发出
[ServiceContractAttribute]
public interface YourContract {
....
}
Run Code Online (Sandbox Code Playgroud)
如果没有ConfigurationName参数,则缺省值是该接口的完全限定名称.
如何解决您的问题
要使其工作,您需要编辑app.config文件并在<endpoint ... contract="...">元素中使用服务合同接口的完全限定名称.
在你的情况下,contract="ServiceReference1.IService1"改成contract="TestServer.IService1"应该这样做.
否则,查看生成的Reference.cs,搜索具有[ServiceContractAttribute]它所在的C#名称空间的接口.
| 归档时间: |
|
| 查看次数: |
9165 次 |
| 最近记录: |