Problem:
Microsoft Visual C# .NET may produce errors when generating client code from WSDL similar to the following example:
<xs:element name="set_xxx">
<xs:complexType>
<xs:sequence>
<xs:element name="xxx" type="XXXtype" />
</xs:sequence>
</xs:complexType>
</xs:element>
Note that the function set_xxx
has a parameter xxx
. Microsoft Visual C# .NET will generate the following code:
public partial class set_xxx {
private string xxxField;
/// <remarks/>
public string xxx {
get {
return this.xxxField;
}
set {
this.xxxField = value;
}
}
}
As you can see, the function has the same name as the class name. This causes the C# compiler to produce the following error:
error CS0542: 'set_xxx': member names cannot be the
same as their enclosing type
Solution:
Create a batch file wsdlc.bat
containing the following code and save it in your project directory:
setlocal
set WS=%1Web References\VZA
copy "%WS%\Reference.map" "%WS%\Reference.discomap"
REM The following block of code should be placed on
REM the same line. Every segment that starts
REM on the next line here, must be placed after
REM the previous one separated by a single space.
"%VS80COMNTOOLS%\..\..\SDK\v2.0\Bin\wsdl.exe"
/l:CS /fields
/out:"%WS%\Reference.cs"
/n:%2.VZA "%WS%\Reference.discomap"
REM End of "The following block of code ..."
del "%WS%\Reference.discomap"
endlocal
exit /b 0
The file generates the new Reference.cs
file (the file containing the proxy classes) fixing the problem described above by generating the regular properties instead of C#-style get/set fields. Do not try to run the file. It will be run automatically after we complete the rest of the steps.
In the Microsoft Visual C# .NET development environment, select Project > Properties menu item. Select Build Events option in the left pane. Now in the right pane, modify the parameter Pre-build Event Command Line to contain the following line:
$(ProjectDir)wsdlc.bat $(ProjectDir) $(ProjectName)
Note: Make sure that the Reference.cs
file is not currently opened in the IDE, otherwise the compiler will use it instead of the new file that will be generated by our batch file.
Select the Build > Build Solution menu option to build your solution. This will take longer than usual because the wsdlc.bat
file that we created will re-generate the proxy classes.
After the build is completed, the Reference.cs
file will contain newly generated stubs. At this point you can remove or comment out the entry that we used in the Project > Properties > Pre-build Event Command Line option. If that's not done, the stubs will be re-generated every time you build your solution.
If you decide to update the client code from WSDLs, repeat the described steps.
The request describing this defect was submitted to Microsoft: #FDBK46565