问题
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);
}
And service:
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:
- 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: 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.
- I need one service with several endpoints.
- I need service like this (preferably on WCF).
Summarizing, I need WCF service with multiple service contracts with duplicate method names in single wsdl. Is there a way to achieve it?
回答1:
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.
Then run the wsdl.exe util from Developer Command Prompt , like this:
wsdl service.wsdl /out:service.cs
Now you have the contracts as wsdl requires, and you can do any changes you need.
Hope it helps.
来源:https://stackoverflow.com/questions/33388676/wcf-service-with-multiple-service-contracts-with-duplicate-method-names-in-singl