The server was unable to process the request due to an internal error. in WCF in .net 4.5 RRS feed

  • Question

  • User751840860 posted


    i  am facing an error wheil i tried to call a   wcf service from asp.net web appln button click.

    my env. SP 2013 / VS 2012 / ASP.NET 4.5 / .NET 4.5

    below is the error thrown:

    The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs


    i want to call a method which has sharepoint 2013 api / and its methods is being written. the wcf is written in a sharepoint server 2013 box and its deployed ona iis site.

    so  when i make a call within the server and from the asp.net web appln button click it throws above error.

    namespace WebApplication1

    public partial class WebForm1 : System.Web.UI.Page
    string result = string.Empty;

    protected void Page_Load(object sender, EventArgs e)


    protected void btnUpload_Click(object sender, EventArgs e)

    ServiceReferenceTest.Service1Client service = new ServiceReferenceTest.Service1Client();
    //WcfService_Garima.Service1 service = new WcfService_Garima.Service1();
    //UploadFileWS.Service1 service = new UploadFileWS.Service1();
    string filename = FileUpload1.FileName;
    // string filepath = FileUpload1.PostedFile.FileName;

    { result = service.GetData();  //am getting error  in this line. added the service reference already.

    } catch (Exception) { throw; } if (result =="upload") { lblResult.Text = "Uploaded"; } else {lblResult.Text = "Failed";  }}}} 


    below is my  wcf service:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Text;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Taxonomy;
    using System.IO;

    namespace WcfService_Garima
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
    public class Service1 : IService1
    public string GetData()

    string strupload = "upload";

    using (SPSite mysite = new SPSite("http://servername:5555/sites/WebService_Garima/"))
    {// replace localhost with the URL of your site
    using (SPWeb myweb = mysite.OpenWeb())
    SPFolder mylibrary = myweb.Folders["WebServiceDocLib"];
    String fileName = "Text1.txt";
    FileStream fileStream = File.OpenRead("D:/Text1.txt");

    // Upload document
    SPFile spfile = mylibrary.Files.Add(fileName, fileStream);

    SPListItem fileItem = spfile.ListItemAllFields;
    //fileItem["MetadataRel"] = "Branch11";

    TaxonomySession session = new TaxonomySession(mysite);TermStore mytermstore = session.DefaultKeywordsTermStore;List<Guid> itemsToAdd = new List<Guid>();

    foreach (Group gr in mytermstore.Groups) { if (gr.Name == "MyGroup")  { TermSet termset = gr.TermSets["MyTermSet"]; TermCollection terms = termset.Terms;
    foreach (Term term in terms) 
    if (term.Name == "MyTerm")
    { itemsToAdd.Add(term.Id); } }  } }

    TaxonomyField taxfld = fileItem.Fields["MetadataRel"] as TaxonomyField;
    Guid[] ids = itemsToAdd.ToArray();
    TermCollection oTerms = session.GetTerms(ids);

    taxfld.SetFieldValue(fileItem, oTerms);


     } } });  return "upload";  }

    public CompositeType GetDataUsingDataContract(CompositeType composite)
    if (composite == null)
    throw new ArgumentNullException("composite");
    if (composite.BoolValue)
    composite.StringValue += "Suffix";
    return composite;

    am still stuck why am getting this error.

    cant we calla  sharepoint dll/api from a  wcf service ?

    help is appreciated

    below is  my web config file:

    <?xml version="1.0"?>

    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
    <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
    <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
    <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true"/>
    <add binding="basicHttpsBinding" scheme="https" />
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
    <modules runAllManagedModulesForAllRequests="true"/>
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
    <directoryBrowse enabled="true"/>


    Thursday, December 5, 2013 4:39 AM