Skip to content

Commit 07b50df

Browse files
authored
dotnet-svcutil: generate compilable code for a service with contract member named System (#5432)
1 parent a4bfc63 commit 07b50df

File tree

6 files changed

+362
-2
lines changed

6 files changed

+362
-2
lines changed

src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Serialization/CodeExporter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ internal CodeMemberProperty CreatePropertyDeclaration(CodeMemberField field, str
347347
CodeMemberProperty prop = new CodeMemberProperty();
348348
prop.Type = new CodeTypeReference(typeName);
349349
prop.Name = name;
350+
if(name.Equals("System"))
351+
{
352+
prop.Name = "SystemMember";
353+
}
350354
prop.Attributes = (prop.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
351355

352356
//add get

src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Serialization/XmlCodeExporter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ private void AddMemberMetadata(CodeMemberField field, CodeAttributeDeclarationCo
718718
string attrName = Accessor.UnescapeName(attribute.Name);
719719
bool sameType = mapping.TypeDesc == member.TypeDesc ||
720720
(member.TypeDesc.IsArrayLike && mapping.TypeDesc == member.TypeDesc.ArrayElementTypeDesc);
721-
bool sameName = attrName == member.Name && !forceUseMemberName;
721+
bool sameName = attrName == member.Name && !forceUseMemberName && member.Name != "System";
722722
bool sameNs = attribute.Namespace == ns;
723723
bool defaultForm = attribute.Form != XmlSchemaForm.Qualified;
724724
ExportAttribute(metadata,
@@ -745,7 +745,7 @@ private void AddMemberMetadata(CodeMemberField field, CodeAttributeDeclarationCo
745745
ElementAccessor element = member.Elements[0];
746746
TypeMapping mapping = (TypeMapping)element.Mapping;
747747
string elemName = Accessor.UnescapeName(element.Name);
748-
bool sameName = ((elemName == member.Name) && !forceUseMemberName);
748+
bool sameName = (elemName == member.Name) && !forceUseMemberName && member.Name != "System";
749749
bool isArray = mapping is ArrayMapping;
750750
bool sameNs = element.Namespace == ns;
751751
bool defaultForm = element.Form != XmlSchemaForm.Unqualified;
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
namespace ContractMemberNamedSystem_NS
11+
{
12+
13+
14+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
15+
[System.ServiceModel.ServiceContractAttribute(Namespace="http://Microsoft.ServiceModel.Samples", ConfigurationName="ContractMemberNamedSystem_NS.IService1")]
16+
public interface IService1
17+
{
18+
19+
[System.ServiceModel.OperationContractAttribute(Action="http://Microsoft.ServiceModel.Samples/IService1/GetData", ReplyAction="http://Microsoft.ServiceModel.Samples/IService1/GetDataResponse")]
20+
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
21+
System.Threading.Tasks.Task<string> GetDataAsync(int value);
22+
23+
[System.ServiceModel.OperationContractAttribute(Action="http://Microsoft.ServiceModel.Samples/IService1/GetDataUsingDataContract", ReplyAction="http://Microsoft.ServiceModel.Samples/IService1/GetDataUsingDataContractResponse")]
24+
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
25+
System.Threading.Tasks.Task<ContractMemberNamedSystem_NS.CompositeType> GetDataUsingDataContractAsync(ContractMemberNamedSystem_NS.CompositeType composite);
26+
27+
[System.ServiceModel.OperationContractAttribute(Action="http://Microsoft.ServiceModel.Samples/IService1/GetDataUsingDataContract2", ReplyAction="http://Microsoft.ServiceModel.Samples/IService1/GetDataUsingDataContract2Response" +
28+
"")]
29+
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
30+
System.Threading.Tasks.Task<ContractMemberNamedSystem_NS.CompositeType2> GetDataUsingDataContract2Async(ContractMemberNamedSystem_NS.CompositeType2 composite);
31+
}
32+
33+
/// <remarks/>
34+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
35+
[System.Diagnostics.DebuggerStepThroughAttribute()]
36+
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://Microsoft.ServiceModel.Samples")]
37+
public partial class CompositeType
38+
{
39+
40+
private string systemField;
41+
42+
private bool boolValueField;
43+
44+
/// <remarks/>
45+
[System.Xml.Serialization.XmlElementAttribute("System", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
46+
public string SystemMember
47+
{
48+
get
49+
{
50+
return this.systemField;
51+
}
52+
set
53+
{
54+
this.systemField = value;
55+
}
56+
}
57+
58+
/// <remarks/>
59+
[System.Xml.Serialization.XmlAttributeAttribute()]
60+
public bool BoolValue
61+
{
62+
get
63+
{
64+
return this.boolValueField;
65+
}
66+
set
67+
{
68+
this.boolValueField = value;
69+
}
70+
}
71+
}
72+
73+
/// <remarks/>
74+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
75+
[System.Diagnostics.DebuggerStepThroughAttribute()]
76+
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://Microsoft.ServiceModel.Samples")]
77+
public partial class CompositeType2
78+
{
79+
80+
private bool systemField;
81+
82+
/// <remarks/>
83+
[System.Xml.Serialization.XmlAttributeAttribute("System", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]
84+
public bool SystemMember
85+
{
86+
get
87+
{
88+
return this.systemField;
89+
}
90+
set
91+
{
92+
this.systemField = value;
93+
}
94+
}
95+
}
96+
97+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
98+
public interface IService1Channel : ContractMemberNamedSystem_NS.IService1, System.ServiceModel.IClientChannel
99+
{
100+
}
101+
102+
[System.Diagnostics.DebuggerStepThroughAttribute()]
103+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
104+
public partial class Service1Client : System.ServiceModel.ClientBase<ContractMemberNamedSystem_NS.IService1>, ContractMemberNamedSystem_NS.IService1
105+
{
106+
107+
/// <summary>
108+
/// Implement this partial method to configure the service endpoint.
109+
/// </summary>
110+
/// <param name="serviceEndpoint">The endpoint to configure</param>
111+
/// <param name="clientCredentials">The client credentials</param>
112+
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);
113+
114+
public Service1Client() :
115+
base(Service1Client.GetDefaultBinding(), Service1Client.GetDefaultEndpointAddress())
116+
{
117+
this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding_IService1.ToString();
118+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
119+
}
120+
121+
public Service1Client(EndpointConfiguration endpointConfiguration) :
122+
base(Service1Client.GetBindingForEndpoint(endpointConfiguration), Service1Client.GetEndpointAddress(endpointConfiguration))
123+
{
124+
this.Endpoint.Name = endpointConfiguration.ToString();
125+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
126+
}
127+
128+
public Service1Client(EndpointConfiguration endpointConfiguration, string remoteAddress) :
129+
base(Service1Client.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
130+
{
131+
this.Endpoint.Name = endpointConfiguration.ToString();
132+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
133+
}
134+
135+
public Service1Client(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
136+
base(Service1Client.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
137+
{
138+
this.Endpoint.Name = endpointConfiguration.ToString();
139+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
140+
}
141+
142+
public Service1Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
143+
base(binding, remoteAddress)
144+
{
145+
}
146+
147+
public System.Threading.Tasks.Task<string> GetDataAsync(int value)
148+
{
149+
return base.Channel.GetDataAsync(value);
150+
}
151+
152+
public System.Threading.Tasks.Task<ContractMemberNamedSystem_NS.CompositeType> GetDataUsingDataContractAsync(ContractMemberNamedSystem_NS.CompositeType composite)
153+
{
154+
return base.Channel.GetDataUsingDataContractAsync(composite);
155+
}
156+
157+
public System.Threading.Tasks.Task<ContractMemberNamedSystem_NS.CompositeType2> GetDataUsingDataContract2Async(ContractMemberNamedSystem_NS.CompositeType2 composite)
158+
{
159+
return base.Channel.GetDataUsingDataContract2Async(composite);
160+
}
161+
162+
public virtual System.Threading.Tasks.Task OpenAsync()
163+
{
164+
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
165+
}
166+
167+
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
168+
{
169+
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_IService1))
170+
{
171+
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
172+
result.MaxBufferSize = int.MaxValue;
173+
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
174+
result.MaxReceivedMessageSize = int.MaxValue;
175+
result.AllowCookies = true;
176+
return result;
177+
}
178+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
179+
}
180+
181+
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
182+
{
183+
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_IService1))
184+
{
185+
return new System.ServiceModel.EndpointAddress("http://localhost:53593/Service1.svc");
186+
}
187+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
188+
}
189+
190+
private static System.ServiceModel.Channels.Binding GetDefaultBinding()
191+
{
192+
return Service1Client.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_IService1);
193+
}
194+
195+
private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
196+
{
197+
return Service1Client.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_IService1);
198+
}
199+
200+
public enum EndpointConfiguration
201+
{
202+
203+
BasicHttpBinding_IService1,
204+
}
205+
}
206+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"providerId": "Microsoft.Tools.ServiceModel.Svcutil",
3+
"version": "99.99.99",
4+
"options": {
5+
"inputs": [
6+
"../../../../../src/dotnet-svcutil/lib/tests/TestCases/wsdl/memberNamedSystem.wsdl"
7+
],
8+
"namespaceMappings": [
9+
"*, ContractMemberNamedSystem_NS"
10+
],
11+
"outputFile": "Reference.cs",
12+
"targetFramework": "N.N",
13+
"typeReuseMode": "None"
14+
}
15+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://Microsoft.ServiceModel.Samples" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" name="Service1" targetNamespace="http://Microsoft.ServiceModel.Samples">
2+
<wsdl:types>
3+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://Microsoft.ServiceModel.Samples">
4+
<xs:element name="GetData">
5+
<xs:complexType>
6+
<xs:sequence>
7+
<xs:element minOccurs="1" maxOccurs="1" name="value" type="xs:int"/>
8+
</xs:sequence>
9+
</xs:complexType>
10+
</xs:element>
11+
<xs:element name="GetDataResponse">
12+
<xs:complexType>
13+
<xs:sequence>
14+
<xs:element minOccurs="0" maxOccurs="1" name="GetDataResult" type="xs:string"/>
15+
</xs:sequence>
16+
</xs:complexType>
17+
</xs:element>
18+
<xs:element name="GetDataUsingDataContract">
19+
<xs:complexType>
20+
<xs:sequence>
21+
<xs:element minOccurs="0" maxOccurs="1" name="composite" type="tns:CompositeType"/>
22+
</xs:sequence>
23+
</xs:complexType>
24+
</xs:element>
25+
<xs:complexType name="CompositeType">
26+
<xs:sequence>
27+
<xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="System" type="xs:string"/>
28+
</xs:sequence>
29+
<xs:attribute name="BoolValue" type="xs:boolean" use="required"/>
30+
</xs:complexType>
31+
<xs:element name="GetDataUsingDataContractResponse">
32+
<xs:complexType>
33+
<xs:sequence>
34+
<xs:element minOccurs="0" maxOccurs="1" name="GetDataUsingDataContractResult" type="tns:CompositeType"/>
35+
</xs:sequence>
36+
</xs:complexType>
37+
</xs:element>
38+
<xs:element name="GetDataUsingDataContract2">
39+
<xs:complexType>
40+
<xs:sequence>
41+
<xs:element minOccurs="0" maxOccurs="1" name="composite" type="tns:CompositeType2"/>
42+
</xs:sequence>
43+
</xs:complexType>
44+
</xs:element>
45+
<xs:complexType name="CompositeType2">
46+
<xs:attribute form="qualified" name="System" type="xs:boolean" use="required"/>
47+
</xs:complexType>
48+
<xs:element name="GetDataUsingDataContract2Response">
49+
<xs:complexType>
50+
<xs:sequence>
51+
<xs:element minOccurs="0" maxOccurs="1" name="GetDataUsingDataContract2Result" type="tns:CompositeType2"/>
52+
</xs:sequence>
53+
</xs:complexType>
54+
</xs:element>
55+
</xs:schema>
56+
</wsdl:types>
57+
<wsdl:message name="IService1_GetData_InputMessage">
58+
<wsdl:part name="parameters" element="tns:GetData"/>
59+
</wsdl:message>
60+
<wsdl:message name="IService1_GetData_OutputMessage">
61+
<wsdl:part name="parameters" element="tns:GetDataResponse"/>
62+
</wsdl:message>
63+
<wsdl:message name="IService1_GetDataUsingDataContract_InputMessage">
64+
<wsdl:part name="parameters" element="tns:GetDataUsingDataContract"/>
65+
</wsdl:message>
66+
<wsdl:message name="IService1_GetDataUsingDataContract_OutputMessage">
67+
<wsdl:part name="parameters" element="tns:GetDataUsingDataContractResponse"/>
68+
</wsdl:message>
69+
<wsdl:message name="IService1_GetDataUsingDataContract2_InputMessage">
70+
<wsdl:part name="parameters" element="tns:GetDataUsingDataContract2"/>
71+
</wsdl:message>
72+
<wsdl:message name="IService1_GetDataUsingDataContract2_OutputMessage">
73+
<wsdl:part name="parameters" element="tns:GetDataUsingDataContract2Response"/>
74+
</wsdl:message>
75+
<wsdl:portType name="IService1">
76+
<wsdl:operation name="GetData">
77+
<wsdl:input wsaw:Action="http://Microsoft.ServiceModel.Samples/IService1/GetData" message="tns:IService1_GetData_InputMessage"/>
78+
<wsdl:output wsaw:Action="http://Microsoft.ServiceModel.Samples/IService1/GetDataResponse" message="tns:IService1_GetData_OutputMessage"/>
79+
</wsdl:operation>
80+
<wsdl:operation name="GetDataUsingDataContract">
81+
<wsdl:input wsaw:Action="http://Microsoft.ServiceModel.Samples/IService1/GetDataUsingDataContract" message="tns:IService1_GetDataUsingDataContract_InputMessage"/>
82+
<wsdl:output wsaw:Action="http://Microsoft.ServiceModel.Samples/IService1/GetDataUsingDataContractResponse" message="tns:IService1_GetDataUsingDataContract_OutputMessage"/>
83+
</wsdl:operation>
84+
<wsdl:operation name="GetDataUsingDataContract2">
85+
<wsdl:input wsaw:Action="http://Microsoft.ServiceModel.Samples/IService1/GetDataUsingDataContract2" message="tns:IService1_GetDataUsingDataContract2_InputMessage"/>
86+
<wsdl:output wsaw:Action="http://Microsoft.ServiceModel.Samples/IService1/GetDataUsingDataContract2Response" message="tns:IService1_GetDataUsingDataContract2_OutputMessage"/>
87+
</wsdl:operation>
88+
</wsdl:portType>
89+
<wsdl:binding name="BasicHttpBinding_IService1" type="tns:IService1">
90+
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
91+
<wsdl:operation name="GetData">
92+
<soap:operation soapAction="http://Microsoft.ServiceModel.Samples/IService1/GetData" style="document"/>
93+
<wsdl:input>
94+
<soap:body use="literal"/>
95+
</wsdl:input>
96+
<wsdl:output>
97+
<soap:body use="literal"/>
98+
</wsdl:output>
99+
</wsdl:operation>
100+
<wsdl:operation name="GetDataUsingDataContract">
101+
<soap:operation soapAction="http://Microsoft.ServiceModel.Samples/IService1/GetDataUsingDataContract" style="document"/>
102+
<wsdl:input>
103+
<soap:body use="literal"/>
104+
</wsdl:input>
105+
<wsdl:output>
106+
<soap:body use="literal"/>
107+
</wsdl:output>
108+
</wsdl:operation>
109+
<wsdl:operation name="GetDataUsingDataContract2">
110+
<soap:operation soapAction="http://Microsoft.ServiceModel.Samples/IService1/GetDataUsingDataContract2" style="document"/>
111+
<wsdl:input>
112+
<soap:body use="literal"/>
113+
</wsdl:input>
114+
<wsdl:output>
115+
<soap:body use="literal"/>
116+
</wsdl:output>
117+
</wsdl:operation>
118+
</wsdl:binding>
119+
<wsdl:service name="Service1">
120+
<wsdl:port name="BasicHttpBinding_IService1" binding="tns:BasicHttpBinding_IService1">
121+
<soap:address location="http://localhost:53593/Service1.svc"/>
122+
</wsdl:port>
123+
</wsdl:service>
124+
</wsdl:definitions>

src/dotnet-svcutil/lib/tests/src/E2ETests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,17 @@ public void WcfRuntimeReliableSessionSvc(string serviceName, bool expectSuccess)
490490
WcfRuntimeSvcs(serviceName, expectSuccess);
491491
}
492492

493+
[Trait("Category", "Test")]
494+
[Fact]
495+
public void ContractMemberNamedSystem()
496+
{
497+
this_TestCaseName = "ContractMemberNamedSystem";
498+
TestFixture();
499+
InitializeE2E(this_TestCaseName);
500+
string wsdlFile = Path.Combine(g_TestCasesDir, "wsdl", "memberNamedSystem.wsdl");
501+
TestSvcutil(AppendCommonOptions(wsdlFile));
502+
}
503+
493504
private void WcfRuntimeSvcs(string serviceName, bool expectSuccess)
494505
{
495506
var testCaseName = serviceName.Replace(".svc", "").Replace("/", "_");

0 commit comments

Comments
 (0)