Answered by:
The server was unable to process the request due to an internal error. in WCF in .net 4.5

Question
-
User751840860 posted
hi,
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
scenario:
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;try
{ 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";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
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);
taxfld.Update();mylibrary.Update();
} } }); 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"?>
<configuration><appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 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"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
</system.serviceModel>
<system.webServer>
<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"/>
</system.webServer></configuration>
Thursday, December 5, 2013 4:39 AM
Answers
-
User-417640953 posted
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 logsHi SaMolPP,
Thank you post the issue to asp.net forum.
This error message indicates there are some mistake happened when we call the service.
For solving this issue, we should better to find what error occurs in the service method "GetData()".
If the wcf project in your solution, you can set a break point to debug it. You can also try to enable WCF trace.
Open config file in svcconfigeditor, from wizard, you can enable tracing and logging. For detail steps, please refer to below article.
There is similar issue with solutions, please check it.
Thanks.
Best Regards!
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, December 9, 2013 9:50 AM