How To Use a User Control (Web Service Call) in a SharePoint Web Part


Written by Chandrasekar Natarajan, Microsoft Premier Field Engineer.


In a typical ASP.NET application, using a User Control is pretty straight forward, we just need to map the control to an ObjectDataSource and bind its settings. But in Microsoft SharePoint Server, when an ObjectDataSource control is used, it will throw the error message saying "The type specified in the TypeNameProperty can be found".  The reason for this is that the proxy class required to connect with the web service is not available in Microsoft SharePoint.  So for this to work, we have to create proxy.

Here’s how we set the proxy:

  • Using WSDL.exe (found under ..\Program Files\Microsoft SDKs\Windows\v6.0A\bin ) run the command wsdl /out:myProxyClass.cs “https://hostServer/WebserviceRoot/WebServiceName.asmx?WSDL”
  • Create the DLL using the proxy cs file. This can be done using CSC.exe ( found under ..\Windows\Microsoft.NET\Framework\vx ) and running the command csc /out:CodeBehindCompiled.dll /target:library CodeBehind_compiled.cs .Note that there is a space between “csc”, “/out…”, “/target…” and “CodeBehind….”.
  • Now deploy the DLL in the bin folder of the SharePoint web application bin directory ( found under ..\inetpub\wwwroot\wss\virtualdirectories\..\bin)
  • Add the SafeControl entry for both the web part and the proxy DLL in the web.config file.
  • In the SharePoint Web part code, make a reference to the proxy class of the ObjectDataSource that we just created using WSDL.exe.
  • In the web.config file, give Full trust level:  <trust level=”Full” originUrl=””/>
  • Now add the web part in the SharePoint page and we should be able to see the web service data in it.

Hope that helps!  Let me know if you have any questions.