WCF Ria Call Method And Not Found - c#

I am using WCF RIA with silverlight 5 and I use LinqToSqlDomainService.
I have one class Like this
[EnableClientAccess()]
public class UsersAndGroups : LinqToSqlDomainService<DataBaseDataContext> {
protected override DataBaseDataContext CreateDataContext() {
return DataBaseConnection.GetNewDataBaseContext();
}
public tblUsersAndGroup Web_CanLogin(string userName, string password) {
...
}
//Will call without error
[Invoke]
public List<spSelectVwUsersAndGroupsResult> Web_SelectView(
BLL.tblUsersAndGroup logedInUser)
{
...
}
}
When I call methods in this class every things is ok.
I have another class:
[EnableClientAccess()]
public class Privileges : MyLinqToSqlDomainService<DataBaseDataContext> {
protected override DataBaseDataContext CreateDataContext() {
return DataBaseConnection.GetNewDataBaseContext();
}
//Will not call and get error!
[Invoke]
public List<spSelectVwUsersAndGroupsResult> Web_SelectView(
BLL.tblUsersAndGroup logedInUser)
{
...
}
//Will call without error!
[Invoke]
public List<spSelectVwUsersAndGroupsResult> Web_SelectViewWithNoParam() {
...
}
}
When I Create method exactly like Web_SelectView in previous calss, when I call it I get "The remote server returned an error: NotFound." error.
When I remove parameter it work, and no error will show to me and method will call.
I see this link about this error:
http://blogs.objectsharp.com/post/2010/04/13/WCF-RIA-Services-%E2%80%9CNot-Found%E2%80%9D-Error-Message.aspx
I see in network tab of my browser in developer tools, I see when call this method it will call but return not found, and result is 500.
Also I put these code in my web config but I didn't see any meaningful error in event log
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true" >
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="myUserTraceSource"
switchValue="Information, ActivityTracing">
<listeners>
<add name="xml"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\logs\Traces.svclog" />
</sharedListeners>
</system.diagnostics>
<system.serviceModel>
<diagnostics wmiProviderEnabled="true">
<messageLogging logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true"
maxMessagesToLog="3000" />
</diagnostics>
</system.serviceModel>
UPDATE:
I edit my web config switchValue="Information, ActivityTracing" to switchValue="All" and now I can see error:
WebHost failed to process a request. Sender Information:
System.ServiceModel.ServiceHostingEnvironment+HostingManager/12036987
Exception: System.ServiceModel.ServiceActivationException: The service
'/Services/BLL-Privileges.svc' cannot be activated due to an exception
during compilation. The exception message is: Operation named
'Web_GetPrivileges' does not conform to the required signature.
Parameter types must be an entity or complex type, a collection of
entities or complex types, or one of the predefined serializable
types.. ---> System.InvalidOperationException: Operation named
'Web_GetPrivileges' does not conform to the required signature.
Parameter types must be an entity or complex type, a collection of
entities or complex types, or one of the predefined serializable
types.
But why "Operation named 'Web_GetPrivileges' does not conform to the required signature." when it work in previous class!!!
Second Edit:
When I remove [Invoke] attribute, no error event will register...
but again I get Not Found! also when I see in browser developer tools no code will back to me, no 200, no 500, or any other....
Thanks

Related

Trying to get to the bottom of a Windows Workflow 4.5 issue

The error I am getting is
"The WorkflowApplication has been aborted because a Load or
LoadRunnableInstance operation threw an exception. Create a new
WorkflowApplication object to try loading another workflow instance."
I am using "workflowapplication" to run the workflow. The workflow instance I'm trying to load (there are a few of them) were created sometime ago and were persisted into the database.
Is there a way to find the exception that was actually thrown during Load or LoadRunnableInstance operation? I caught this error in the "aborted" event on the workflowapplication object, but it does not tell me the error that was thrown during load.
New addition
I stuck the following code in my web.config to get more details about the above exception:
<system.diagnostics>
<sources>
<source name="System.Activities.DurableInstancing" switchValue="Verbose">
<listeners>
<add name="textListener" />
<remove name="Default" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="textListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="c:\Log\persistenceproblem.txt" traceOutputOptions="ProcessId, DateTime" />
</sharedListeners>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="textListener" />
</listeners>
</trace>
</system.diagnostics>
This pointed me to the exception
System.Activities.DurableInstancing Warning: 131075 : http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspxThrowing an exception. Source: System.Activities.DurableInstancing 4.0.0.0. Exception details: System.Runtime.DurableInstancing.InstancePersistenceCommandException: The execution of the InstancePersistenceCommand named {urn:schemas-microsoft-com:System.Activities.Persistence/command}LoadWorkflow was interrupted by an error. ---> System.Runtime.Serialization.SerializationException: The deserializer cannot load the type to deserialize because type 'System.Data.Entity.DynamicProxies.VacancyQuestionFormA_0A0432BFEF4023483E1B33251D8373454EAC6EDF2B2C6F312A4F606F45AF30E8' could not be found in assembly 'EntityFrameworkDynamicProxies-ConnectCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Check that the type being serialized has the same contract as the type being deserialized and the same assembly is used.
So now my issues is how to deal with Dynamic proxies that are being serialized. From what I've read, these are on demand so won't be guaranteed to be in the Dlls especially as we have multiple developers.
We already have clients that will have instances of the workflow with serialized Proxy classes.
My question now becomes:
Is there a built in way for Windows Workflow to deal with Serialized Proxy classes more eloquently?

WCF Diagnostics Message Logging With Unique Id

I'm logging messages for WCF web service using System.Diagnostics System.ServiceModel.MessageLogging with configuration below. And I extended
TraceListener class as:
public class FormattedTraceListener : TraceListener
{
static readonly Logger logger = new Logger();
public FormattedTraceListener()
: base(string.Empty)
{
}
public override void TraceData(TraceEventCache eventCache,String source,TraceEventType eventType,**Int32 id,**Object data)
{
//....
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" >
<listeners>
<add name="pretty" />
<remove name="Default"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="pretty" lockItem="true" type="LoggingTest.FormattedXmlWriterTraceListener,LoggingTest" />
</sharedListeners>
<trace autoflush="true" indentsize="4">
</trace>
</system.diagnostics>
....
<diagnostics >
<messageLogging
logEntireMessage="true"
logMalformedMessages="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"
maxMessagesToLog="-1"
maxSizeOfMessageToLog="134217728">
<filters >
<add xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">/s:Envelope</add>
<add xmlns:s="http://www.w3.org/2003/05/soap-envelope">/s:Envelope</add>
</filters>
</messageLogging>
<endToEndTracing propagateActivity="true" activityTracing="true" messageFlowTracing="true" />
</diagnostics>
</system.serviceModel>
TraceData method fired twice (for request and response) for each service call.
However, when method is hit, the id parameter is always 0.
I need a unique id in logging text to match request and response log. How can I specify that?
Your approach is not right. The TraceData(int id) field is not a unique id for the WCF request. It's the application defined code for the event type.
Just use the standard WCF trace classes and view correlated traces. If I understand what you are trying to accomplish in matching up request to response, the default behavior already meets your requirements.

How to filter/disable exceptions being logged in WCF trace?

Is there a way to prevent a type of exceptions from being logged in the WCF trace?
And even better, is there a way to prevent one particular exception (I mean one exception being thrown at a specific code line) from being logged?
Explanations:
I am working on two Windows service (A) & (B). On service (A), I have enabled WCF trace in my app.config file, as follows:
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Warning"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\WCF-log.txt" />
</listeners>
</source>
</sources>
</system.diagnostics>
On this service (A), I have some code used to detect if the other service (B) is down, that looks like that:
try {
serviceB.Ping(); // Exception is thrown here when serviceB is down, and
// logged in the C:\WCF-log.txt file
} catch {
// Manage failed ping (log...)
}
Now, the service (B) can be sometimes down, and that's normal. I would like those raised exception not to be logged in the WCF trace, because they are already treated by my application, and I want to have to look into the C:\WCF-log.txt file only if there is a "real" problem.
You should add filter type in trace listener configuration as below
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Warning"
propagateActivity="true">
<listeners >
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\WCF-log.txt" >
<filter type="FilterExceptions"/>
</add>
</listeners>
</source>
</sources>
</system.diagnostics>
And the FilterException type should inherit System.Diagnostics.TraceListener and override ShouldFilter method as below
public class FilterExceptions : TraceFilter
{
public override bool ShouldTrace(TraceEventCache cache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] args, object data1, object[] data)
{
// Add exception filter in below if when event type is error
if (eventType == TraceEventType.Error)
{
return false;
}
return true;
}
}

Can I turn off tracing for a single assembly that my code references?

I have a certain framework of code, and I have a TraceListener defined for two reasons:
Back-compatibility with a lot of the old logging that was done via Trace.Write until we update it, and
It's nice to be able to instrument the other assemblies our code references if we need to.
However, I have one assembly (not ours) that logs a lot of pointless data that doesn't help us debug anything. How can I turn off tracing for this one assembly (or, alternately, the facade project we built around it), while leaving it on for the rest of the application?
I've tried various flavors of configuration in our facade project, usually looking like the following, to no avail. I've tried adding <remove> elements that match the <add> elements which setup the logging in the first place, tried <clear>ing them, setting <trace enabled="false"> and at least three other attempts. Thanks for any help you can provide!
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<clear/>
</listeners>
</trace>
<switches>
</switches>
</system.diagnostics>
You can write your own trace filter, for use with your TraceListener. Inside this filter you can look for your assembly in stackTrace and turn off event tracing.
In my case I wrote filter (see: DotNetOpenAuthFilter) based on EventTypeFilter, which filters events only from the DotNetOpenAuth library.
Then connect the filter to the listener in the web.config:
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add name="console" type="System.Diagnostics.ConsoleTraceListener" >
<filter type="Common.Log.DotNetOpenAuthFilter, Common" initializeData="Warning" />
</add>
</listeners>
</trace>
</system.diagnostics>
</configuration>
Use TraceSource.
Initialize it in your trace source.
TraceSource logger = new TraceSource("Class1");
Call it from critical points in code:
logger.TraceInformation("Hello from Class1");
Be sure to edit your application configuration:
<system.diagnostics>
<trace autoflush="true"/>
<sources>
<source name="Class1" switchName="Class1Switch" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="console"></add>
<add name="csv" />
<!-- or you can add your own listener here -->
</listeners>
</source>
</sources>
<switches>
<add name="Class1Switch" value="Information" />
</switches>
<sharedListeners>
<add name="console" type="System.Diagnostics.ConsoleTraceListener" />
<add name="csv" type="System.Diagnostics.DelimitedListTraceListener"
delimiter="|" initializeData="d:\data\tracing\trace.log"
traceOutputOptions="Timestamp, ThreadId, LogicalOperationStack, DateTime, ProcessId">
</add>
</sharedListeners>
</system.diagnostics>
If say, you want to only log errors, change the switch:
<add name="Class1Switch" value="Error" />
To switch it completely off:
<add name="Class1Switch" value="Off" />

Why isn't my invalid WCF message being logged?

I've got a WCF client communicating with a WCF service using [DataContract] types, and I'm getting a serialization error:
The formatter threw an exception while trying to deserialize the message: There was an error
while trying to deserialize parameter http://www.example.com/2007/09/Example:ExampleResult.
The InnerException message was 'Deserialized object with reference id 'i3' not found in
stream.'. Please see InnerException for more details.
Normally, I'd simply crank up the tracing and see exactly what happened, but in this case, I can't get the offending (response) message to appear in the log.
My configuration looks like this:
<system.serviceModel>
... (more stuff)
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true"
logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="true"
maxMessagesToLog="10000" maxSizeOfMessageToLog="81920000" />
</diagnostics>
</system.serviceModel>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="wcf_listener" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="wcf_listener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="wcf_listener" initializeData="tracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener" />
</sharedListeners>
</system.diagnostics>
In the resulting log file, I get the outbound message logged, and then the exception logged. I never see the incoming message. What am I doing wrong here?
It seems that the problem related to your flooded data between the service and the client.
Please refer to my post here

Categories