If you are using Microsoft Visual Studio 2005, you may get errors when generating client code from WSDL. The errors may look similar to the following:
error CS0542: 'set_xxx': member names cannot be the same as their enclosing type
The error is produced by the C# compiler when generating the code for the XML schema 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;
public string xxx {
get {
return this.xxxField;
}
set {
this.xxxField = value;
}
}
}
As you can see, the function name is the same as the class name. This causes the compiler to produce those errors.
Resolution:
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"
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\wsdl.exe" /l:CS /fields /out:"%WS%\Reference.cs" /n:%2.VZA "%WS%\Reference.discomap"
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 by 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 the newly generated stubs. At this point you can remove or comment out the entry that used in the Project > Properties > Pre-build Event Command Line option. If you do not, the stubs will be re-generated every time you build your solution.
If you decide to update the client code from WSDL located on our Web server again, make sure that you repeat the steps described here again.
The request describing this defect was submitted to Microsoft: #FDBK46565