Share via


Cannot compile Web Service proxy.

I recently worked an issue where we were getting the following error in SharePoint Designer when trying to create a connection to a WCF Service for a new External Content Type.

Connection to the WCF service that has connection name <Name> cannot be established.

Error Details

Cannot compile Web Service proxy.

 

This error isn't very detailed, so to get more information I collected a BCS client-side trace  from the machine where I was using SharePoint Designer. In the BCS trace I could see a series of error entries similar to this:

Error during Windows Communication Foundation Proxy compile: c:\Users\waltwa\AppData\Local\Temp\1\v4akfd3i.0.cs(563,60) : error CS0120: An object reference is required for the nonstatic field, method, or property 'BCSServiceProxy.ZduetWaltTestClose.System.get'

Error during Windows Communication Foundation Proxy compile: c:\Users\waltwa\AppData\Local\Temp\1\v4akfd3i.0.cs(563,67) : error CS0117: 'string' does not contain a definition for 'Xml'

 

In the WSDL (from the Service Metadata URL) I could see that in the ZduetWaltTestClose complex type there is an element named "System".

 

If you look at the WSDL you will see an element named "System" in the complexType "ZduetWaltTestClose":

 <xsd:complexType name="ZduetWaltTestClose">
    <xsd:sequence>
        <xsd:element name="Type" type="n0:char1" /> 
        <xsd:element name="Id" type="n0:char20" /> 
        <xsd:element name="Number" type="n0:numeric3" /> 
        <xsd:element name="Message" type="n0:char220" /> 
        <xsd:element name="Row" type="xsd:int" /> 
        <xsd:element name="Field" type="n0:char30" /> 
        <xsd:element name="System" type="n0:char10" /> 
    </xsd:sequence>
</xsd:complexType>

 

So at this point, we know that the compiler is failing when trying to work with 'BCSServiceProxy.ZduetWaltTestClose.System.get'.

Cause

The problem here is that during the creation of the Connection, a proxy DLL is generated based on the WSDL that is specified in the "Service Metadata URL" field of the WCF Connection dialog box.  The first step is to convert the WSDL to a C# .NET source file (a .cs file) and this works fine.  The next step is that the C# Compiler (CSC.EXE) tries to compile the .cs file into a DLL but this fails due to the method named "System".  To see the problem outside of SharePoint Designer, if you have Visual Studio, you can use the WSDL.EXE (note SvcUtil.exe is a better choice – see Update below) and CSC.EXE tools.

1. Save your WSDL to disk and give it a .wsdl extension.

2. In a Visual Studio Command Prompt, run wsdl.exe and pass it your .wsdl file.

    For example:

           WSDL.EXE C:\Temp\WaltsTest.wsdl

    You should get output similar to:

    Writing file 'C:\Temp\Z_WALT.CS'.

3. Next, run:   CSC.EXE /t:library C:\TEMP\Z_WALT.cs

    This should result in the same series of errors that you see in the BCS Client trace:

error CS0120: An object reference is required for the nonstatic field, method, or property 'BCSServiceProxy.ZduetWaltTestClose.System.get'

To fix this we renamed the "System" field to "SystemName" on the SAP side and then it imported without any problems.

Update

I worked on another “Cannot compile Web Service proxy” issue recently and the steps above to use WSDL.EXE to generate the .cs file were not sufficient to show the problem as both wsdl.exe and csc.exe commands completed without error.  I found that using the Windows SDK tool SvcUtil.exe is a better representation of what SharePoint Designer is doing to generate proxies for WCF services and using SvcUtil.exe I was able to see the compiler error outside of SPD.

1. Save your WSDL to disk and give it a .wsdl extension.

2. In a Visual Studio Command Prompt, run SvcUtil.exe and pass it your .wsdl file

    For example:  
          SvcUtil.exe C:\Temp\WaltsTest.wsdl

    You should see output similar to:

          Generating Files…

          C:\Temp\Z_WALT.CS

          C:\Temp\output.config

 

3. Next, run:   CSC.EXE /t:library C:\TEMP\Z_WALT.cs

This resulted in the following error:

Z_WALT.cs(219,22): error CS0101: The namespace '<global namespace>' already contains a definition for 'Walt'

Z_WALT.cs(17,18): (Location of symbol related to previous error)

In this case, the WSDL contained both a ComplexType and a PortType with the same name ‘Walt’. The PortType ‘Walt’ from the WSDL had resulted in an Interface named ‘Walt’ on line 17 of the Z_WALT.cs file and the ComplexType ‘Walt’ from the WSDL had resulted in a Class named ‘Walt’ on line 219 which resulted in the compiler error.

To fix this we renamed the PortType ‘Walt’ on the SAP side.

Resolution

To test the resolutions before making the changes SAP side, you can make changes to the downloaded .wsdl and then use the SvcUtil.EXE and CSC.EXE steps mentioned above to confirm that the .cs code can be compiled without error.