具有多个服务契约的 WCF 服务,在单个 wsdl 中具有重复的方法名称 [英] WCF service with multiple service contracts with duplicate method names in single wsdl
问题描述
Continuing this and this questions. I have two service contract with the same methods:
[ServiceContract]
public interface IServices1
{
[OperationContract]
string GetData(int value);
}
[ServiceContract]
public interface IServices2
{
[OperationContract]
string GetData(int value);
}
和服务:
public class Service : IServices1, IServices2
{
string IServices1.GetData(int value)
{
return string.Format("You entered: {0}", value);
}
string IServices2.GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
根据我无法控制的原因:
According to reasons beyond my control:
- 这个不适合我的答案,我需要保留原来的名字.
- 这个答案不适合我,我需要单个 wsdl 文件.如果您使用不同的命名空间,当您尝试从服务主页打开单个 wsdl (http://addresToService/Service.svc?singleWsdl) 得到错误:
- this answer not for me, I need to keep the original names.
- this answer not for me, I need single wsdl file. If you use a different namespaces, when you try to open single wsdl from service main page (http://addresToService/Service.svc?singleWsdl) get the error:
System.NotSupportedException:无法为此服务生成单个 WSDL 文档.找到了多个服务合同命名空间(IServices1、IServices2).确保您的所有服务合同都具有相同的命名空间.
System.NotSupportedException: A single WSDL document could not be generated for this service. Multiple service contract namespaces were found (IServices1, IServices2). Ensure that all your service contracts have the same namespace.
- 我需要具有多个端点的一项服务.
- 我需要像 this 这样的服务(最好在 WCF 上).
- I need one service with several endpoints.
- I need service like this (preferably on WCF).
总而言之,我需要具有多个服务合同的 WCF 服务,并且在单个 wsdl 中具有重复的方法名称.有没有办法实现它?
Summarizing, I need WCF service with multiple service contracts with duplicate method names in single wsdl. Is there a way to achieve it?
推荐答案
从 wsdl 文件生成您的类.将 http://pastebin.com/277DFF7H 的内容保存在一个文件中,例如service.wsdl".不要忘记 <?xml version="1.0" encoding="UTF-8"?>
标签必须首先像第一列.
Generate your classes from the wsdl file.
Save the content of http://pastebin.com/277DFF7H in a file, like "service.wsdl". Don't forget that <?xml version="1.0" encoding="UTF-8"?>
tag must be at first like, first column.
然后从 Developer Command Prompt 运行 wsdl.exe 实用程序,如下所示:
Then run the wsdl.exe util from Developer Command Prompt , like this:
wsdl service.wsdl /out:service.cs
现在您拥有 wsdl 所需的合同,您可以进行任何需要的更改.
Now you have the contracts as wsdl requires, and you can do any changes you need.
希望有帮助.
这篇关于具有多个服务契约的 WCF 服务,在单个 wsdl 中具有重复的方法名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!