Debugging WCF Web Service Faults - c#-4.0

I am trying to debug a web service exception. I have both the client and the service running in debug mode in Visual Studio 2010, C#, .net 4.0 framework.
When I run the client, and get it to call the web service, I get an exception:
Type: System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
Error Message: The type initializer for 'myService.Service' threw an exception.
Source: mscorlib
However, the service shows no exceptions whatsoever.
The stack trace that I got seems to indicate that the call was made, and the reply was being handled (even if the reply was an exception):
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Can someone give pointers on what else I need to do to debug this?
I'm currently setting up the Service Trace Viewer tool to see if that will tell me anything more.

The error message suggests that your service class myService.Service has a static constructor or field initializer expression with a bug in it, causing an unhandled exception to escape the static ctor when the Service type is loaded.
In the service host process under the debugger, just put breakpoints on the static ctor and field initializer expressions, and step until the underlying exception occurs.
The Fusion (.NET class loader) Log will likely get you there also, if you know how to use that.

Error is likely a missing dependency on server side. Launch fuslogvw.exe, enable failure logging, reproduce the problem and look for related failure records.

Related

Call WCF service from a background thread

I’m working on a piece of code which would take in an API request to a WebAPI controller and through that invoke a WCF web service. This would block until the WCF service responded and cause issues such as timeouts and performance problems. I can't use async/await for this particular use case for a number of reasons beyond my control.
I’m looking at kicking this WCF call off on a separate thread, so in the WebAPI controller I do something like:
New Thread(()=>{
//Call WCF service here
//Do something with the response
}).Start();
However, the code is blowing up. The line that calls the WCF service was moved into the above codeblock unchanged, but now I’m getting:
Cannot access a disposed object. Object name:
'System.ServiceModel.Channels.ServiceChannel'.
Looking at the stack trace when the exception is thrown, I can see the server stack trace as follows:
Server stack trace: at
System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable()
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan
timeout) at
System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel
channel, TimeSpan timeout) at
System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan
timeout, CallOnceManager cascade) at
System.ServiceModel.Channels.ServiceChannel.Call(String action,
Boolean oneway, ProxyOperationRuntime operation, Object[] ins,
Object[] outs, TimeSpan timeout) at
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
methodCall, ProxyOperationRuntime operation) at
System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
message)
Im not hugely experienced with WCF so wondered if there was some quirk regarding calling this service in a background thread or if there was something else I needed to do instead?
I’ve tried Googling this but all the results are pertaining to calling a background thread from within a WCF service, not calling a WCF service from a background.
Any ideas?
I am pretty much sure, that you creating instance of WCF service outside thread. So previously it looked like:
using(var client = new WcfServiceClient())
{
client.CallSomeMethod();
}
And you changed it to something like:
using(var client = new WcfServiceClient())
{
new Thread(() => {
client.CallSomeMethod();
}).Start();
}
And what you need to is to move client creation into Thread:
new Thread(() => {
using(var client = new WcfServiceClient())
{
client.CallSomeMethod();
}
}).Start();
}
So I figured this out in the end. It was a Unity problem. For some reason, whereas the existing code was:
container.RegisterType<IMyServiceWrapper, MyServiceImplementation>()
I had to explicitly tell Unity how to resolve the constructor parameter:
container.RegisterType<IMyServiceWrapper, MyServiceImplementation>(
new InjectionConstructor(container.Resolve<IMyDependentService>()));
Unfortunately, I have no idea why this was required or why it fixed it?

ACS azure for published application

Hy guys ,
I developed a WebForms application using VS 2012 . I've published it on Azure .
After that I integrated ACS ( i've set the URL to my allready published application)
I published the application again , but it doesn't work .
After I've registered myself (for ex using Yahoo or LiveID) I've got this error :
Server Error in '/' Application.
The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.Cryptography.CryptographicException: The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[CryptographicException: The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.]
System.Security.Cryptography.ProtectedData.Protect(Byte[] userData, Byte[] optionalEntropy, DataProtectionScope scope) +379
System.IdentityModel.ProtectedDataCookieTransform.Encode(Byte[] value) +52
[InvalidOperationException: ID1074: A CryptographicException occurred when attempting to encrypt the cookie using the ProtectedData API (see inner exception for details). If you are using IIS 7.5, this could be due to the loadUserProfile setting on the Application Pool being set to false. ]
System.IdentityModel.ProtectedDataCookieTransform.Encode(Byte[] value) +167
System.IdentityModel.Tokens.SessionSecurityTokenHandler.ApplyTransforms(Byte[] cookie, Boolean outbound) +57
System.IdentityModel.Tokens.SessionSecurityTokenHandler.WriteToken(XmlWriter writer, SecurityToken token) +658
System.IdentityModel.Tokens.SessionSecurityTokenHandler.WriteToken(SessionSecurityToken sessionToken) +86
System.IdentityModel.Services.SessionAuthenticationModule.WriteSessionTokenToCookie(SessionSecurityToken sessionToken) +144
System.IdentityModel.Services.SessionAuthenticationModule.AuthenticateSessionSecurityToken(SessionSecurityToken sessionToken, Boolean writeCookie) +82
System.IdentityModel.Services.WSFederationAuthenticationModule.SetPrincipalAndWriteSessionToken(SessionSecurityToken sessionToken, Boolean isSession) +216
System.IdentityModel.Services.WSFederationAuthenticationModule.SignInWithResponseMessage(HttpRequestBase request) +860
System.IdentityModel.Services.WSFederationAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs args) +369
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
What should i do ?
I've set the URL's correctly. I don't have in web.config any reffernces of "localhost"..
I don't know what I must set additionly for this to work..
By default WIF uses DPAPI to encrypt cookies. Switch to cert based encryption. See this answer:
Is it possible to run WIF without LoadUserProfile = True
Vittorio Bertocci answers the question here
http://www.cloudidentity.com/blog/2013/01/28/running-wif-based-apps-in-windows-azure-web-sites-4/
DPAPI is not available in the cloud web apps and 4.5 has a simple solutions

CRM 2011 Service Connection Issue With CallerID

I have an application that connects to the CRM 2011 service. When I attach to the service without a CallerID I can grab the data without error. The hitch comes when I add the caller ID to the connection. I receive this error message (might seem familiar):
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 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 3.0 SDK documentation and inspect the
server trace logs. Server stack trace: at
System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message
reply, MessageFault fault, String action, MessageVersion version,
FaultConverter faultConverter) at
System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime
operation, ProxyRpc& rpc) at
System.ServiceModel.Channels.ServiceChannel.Call(String action,
Boolean oneway, ProxyOperationRuntime operation, Object[] ins,
Object[] outs, TimeSpan timeout) at
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
methodCall, ProxyOperationRuntime operation) at
System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
message) Exception rethrown at [0]: at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg) at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type) at
Microsoft.Xrm.Sdk.IOrganizationService.Retrieve(String entityName,
Guid id, ColumnSet columnSet) at
Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.RetrieveCore(String
entityName, Guid id, ColumnSet columnSet) at
Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Retrieve(String
entityName, Guid id, ColumnSet columnSet) at
Hanlon.Data.CRM.DataObjectBase.Retrieve(Guid identity) at
Hanlon.Data.CRM.Advisor.Fill(Guid advisor_identity) at
HypotheticalReportCrmSite.HypotheticalReport.AcceptanceWorkFlow()
Does anyone have any ideas on why this is happening or how I can find out what the error is more specifically? The application works on both Test and User Acceptance servers but blows up on Production.
Clearly there are a number of reasons why this may work differently on different servers, some places to start looking would be the setup/installation/permissions on the different servers including CRM, SQL, Active Directory (although I might assume AD would be the same).
Is there any difference in the proxy used for the Prod server compared to that on the Test/UAT systems?
Are all the relevant versions of the .NET framework available on the Prod server?
Are the same assemblies installed in the GAC?
Is SQL more locked down for the Prod server?
Were the CRM installations on the Prod server completed according to the same specifications as the Test and UAT servers? Were they installed by the same party?
Again, these are all just ideas, but it would seem that the differences between the servers would be the place to look and the installations of the key products would be a good place to start, followed perhaps by looking at the .NET framework etc.
Apologies if the answer is quite generic, but as you have found the specific error doesn't appear to have revealed a smoking gun.
I'd be interested to know what you find.

SharePoint Performance Point Custom Filter Renderer Class Error

I have two servers (Server A and Server B) in one SharePoint 2010 farm. I am getting following error on SharePoint Dashboard page while using the custom PPS filter webpart on Dashboard.
I have used Microsoft PerformancePoint Services SDK sample as base and created a custom Rendered class to define in FilterEditor Class as
filter.RendererClassName = typeof(CustomFilter).AssemblyQualifiedName;
Critial Error:
0x0500 PerformancePoint Service PerformancePoint Services 4 Critical An unexpected error occurred. Error 20798. Exception details: System.ServiceModel.FaultException: An unknown error has occurred. If the problem persists contact an administrator. There may be additional information in the server application event log. Server stack trace: at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]:... c9c0a044-c18d-4374-ad6f-e99d2a2959cd
Critial Error:
PerformancePoint Services 4 Critical ... at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at Microsoft.PerformancePoint.Scorecards.IBIMonitoringServiceApplication.GetFilterDependencies(RepositoryLocation filterLocation) at Microsoft.PerformancePoint.Scorecards.BIMonitoringServiceApplicationProxy.<>c_DisplayClassbb.b_ba(IBIMonitoringServiceApplication channel) at Microsoft.PerformancePoint.Scorecards.BIMonitoringServiceApplicationProxy.ExecuteOnChannel(CodeBlock codeBlock) c9c0a044-c18d-4374-ad6f-e99d2a2959cd
And finally:
PerformancePoint Services ef8z Critical An exception occurred while rendering a Web control. The following diagnostic information might help to determine the cause of this problem: Microsoft.PerformancePoint.Scorecards.BpmException: There was a problem preparing the WebPart for display. PerformancePoint Services error code 20700. c9c0a044-c18d-4374-ad6f-e99d2a2959cd
Please advice what I should do to overcome this problem.
In the web.config file, how did you specifiy the assembly for the renderer? It should be in this format:
Namespace.Class name, DLL name, DLL version number, DLL culture, DLL public key token
And it should look something like the RendererClass in this example:
<CustomFCO type="Filter" subType="SampleFilter">
<Resources FCOName="Custom Filter" FCODescription="This is my custom filter." />
<RendererClass name="Microsoft.PerformancePoint.Scorecards.ServerRendering.MultiSelectTreeViewControl,
Microsoft.PerformancePoint.Scorecards.ServerRendering, Version=14.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<EditorURI uri="/_layouts/SampleFilterEditor.aspx" />
</CustomFCO>
(http://msdn.microsoft.com/en-us/library/ee556434.aspx)

Sharepoint Word Automation Services Exception

I am trying to do a server side doc/docx to pdf conversion using Word Automation Services. I am using the basic sample from MSDN, Link: http://msdn.microsoft.com/en-us/library/ff742315.aspx and encounter an obscure error every time ConversionJob's Start() method is called. Here's the exception;
Source: mscorlib
Message: An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.
InnerException: System.ServiceModel.FaultException: An error occurred when verifying security for the message.
StackTrace: Server stack trace: at System.ServiceModel.Channels.SecurityChannelFactory1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout) at System.ServiceModel.Channels.SecurityChannelFactory1.SecurityRequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at Microsoft.IdentityModel.Protocols.WSTrust.IWSTrustContract.Issue(Message message) at Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannel.Issue(RequestSecurityToken rst, RequestSecurityTokenResponse& rstr) at Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannel.Issue(RequestSecurityToken rst) at Microsoft.SharePoint.SPSecurityContext.SecurityTokenForContext(Uri context, Boolean bearerToken, SecurityToken onBehalfOf, SecurityToken actAs, SecurityToken delegateTo) at Microsoft.SharePoint.SPSecurityContext.<>c_DisplayClass7.b_6() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurityContext.GetProcessSecurityTokenForServiceContext() at Microsoft.SharePoint.SPSecurityContext.SecurityTokenForServiceContext(Uri contextUri) at Microsoft.SharePoint.SPChannelFactoryOperations.InternalCreateChannelActingAsLoggedOnUser[TChannel](ChannelFactory1 factory, EndpointAddress address, Uri via) at Microsoft.SharePoint.SPChannelFactoryOperations.CreateChannelActingAsLoggedOnUser[TChannel](ChannelFactory1 factory, EndpointAddress address) at Microsoft.Office.Word.Server.Service.ConfigChannelFactory1.CreateChannel() at Microsoft.Office.Word.Server.Service.WordServiceApplicationProxy.AddJob(Ucid ucid, Nullable1 subscriptionId, SPUserToken userToken, ConversionJobSettings settings, String name) at Microsoft.Office.Word.Server.Conversions.ConversionJob.Start() at VisualWebPartProject1.VisualWebPart1.VisualWebPart1UserControl.Page_Load(Object sender, EventArgs e)
I tried the same code inside one of our sharepoint sites, still got the same error. Trying this inside a Wcf Service has same result. I made a visual web part for this and same error. Changing user accounts or RunWithElevatedPrivileges didn't help either.
Since the sample requires Microsoft.Sharepoint and Microsoft.Office.Word.Server.Conversions namespaces, I have to run this code on some server having sharepoint installed. So IMHO, the time skew issue is not related as the code is ran over the same server where Word Automation Services are present. I expect some configuration problems on the sharepoint server side, but I don’t know what to check.
Let me know if any other details are required, thanks.
Without having more specifics around the code you're running it's hard to say. Take a look at the overall Word Automation Services content in the SDK.
Also, check out the topics under "Configuring Word Automation Services for Development" in the SDK in particular.

Resources