I faced The Below Problem Few Days Back With The follwing Error .
"Could not resolve mscorlib for target framework '.NETFramework,Version=v4.0'. This can happen if the target framework is not installed or if the framework moniker is incorrectly formatted."
OR
Build Failed Without Errror Description
Solution :
As I as Using XP It was MAX_PATH I just Kept the Path below "240".
Means :-
C://MyProject/Folder/Foder..
The path Should be Under "256 Character".
That Solved It.
Hope It Help Somebody.
WCF
Menu
Thursday, April 21, 2011
Saturday, February 19, 2011
enterprise library 5.0 Logging With WCF
Few days back I was asked to Integrate The Application Block Logging with WCF TraceListener.
I searched The Net No Usefull Tutorial was Found So good Leads but They where not Integrating Application Block with So I decided to Write My Own.
The code is very simple
So let Start,
1 } I Using Vs2010 & Enterprise Libary
I Have used
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=bcb166f7-dd16-448b-a152-9845760d9b4c
Downloaded Libary from above link.
2} Create WCF Application
3} Know Edit The Web.config File
4 } You Will See The Window For Editing
5} Selecting Rolling Filat File Logging
6} Remove The Default Listener
7} Select Rolling Flat File
8} Do the Setting For Rolling Flat File
9} Save and Move to web.config file add Digonistic Tag
10} Adding Diagontsic to to ServiceModel Tag
11} Know Create cs File Which would work as Trace Listener and Refrence file for Microsoft Enterprise Libary
12 } Assemblies Selected from bin
13} Code Used For Credating Listener
14} Know Created The Website and Add service Refernce for Testing
15} Code Used for Calling Service Refernce
16} When We Click Simple Button
17} Know Checking The data Which is Requested from Flat file
18 } Checking Response in Rolling Flat file
Know Code of web.config, TraceListener, & WCf service
19} Web.config code
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<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>
</sources>
<sharedListeners>
<add name="xml" type="WCFApplicationLogging.WebTraceListener,WCFApplicationLogging" />
</sharedListeners>
</system.diagnostics>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="E:\EnterPrise_Libary\Sample\rolling.log" rollFileExistsBehavior="Increment"
rollSizeKB="124" maxArchivedFiles="1200" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
Extended Properties: {dictionary({key} - {value}{newline})}"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings />
<client />
<diagnostics>
<messageLogging logEntireMessage="true"
logMalformedMessages="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"/>
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
20} WebTraceListener.cs
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging.ExtraInformation;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.EnterpriseLibrary.Logging.Filters;
using System.Diagnostics;
using System.Collections.Generic;
namespace WCFApplicationLogging
{
public class WebTraceListener : TraceListener
{
private LogWriter logWriter = null;
private TraceManager traceManager = null;
IDictionary categories = null;
public WebTraceListener()
{
this.logWriter = EnterpriseLibraryContainer.Current.GetInstance();
this.traceManager = EnterpriseLibraryContainer.Current.GetInstance();
this.categories = this.logWriter.TraceSources;
}
public override void Write(string message)
{
this.logWriter.Write(message, "Avinash test");
}
public override void WriteLine(string message)
{
this.logWriter.Write(message, "Avinash test");
}
}
20 } WCF service
I have used Bolier plate code Given by Microsoft so it is default code.
I searched The Net No Usefull Tutorial was Found So good Leads but They where not Integrating Application Block with So I decided to Write My Own.
The code is very simple
So let Start,
1 } I Using Vs2010 & Enterprise Libary
I Have used
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=bcb166f7-dd16-448b-a152-9845760d9b4c
Downloaded Libary from above link.
2} Create WCF Application
3} Know Edit The Web.config File
4 } You Will See The Window For Editing
5} Selecting Rolling Filat File Logging
6} Remove The Default Listener
7} Select Rolling Flat File
8} Do the Setting For Rolling Flat File
9} Save and Move to web.config file add Digonistic Tag
10} Adding Diagontsic to to ServiceModel Tag
11} Know Create cs File Which would work as Trace Listener and Refrence file for Microsoft Enterprise Libary
12 } Assemblies Selected from bin
13} Code Used For Credating Listener
14} Know Created The Website and Add service Refernce for Testing
15} Code Used for Calling Service Refernce
16} When We Click Simple Button
17} Know Checking The data Which is Requested from Flat file
18 } Checking Response in Rolling Flat file
Know Code of web.config, TraceListener, & WCf service
19} Web.config code
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<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>
</sources>
<sharedListeners>
<add name="xml" type="WCFApplicationLogging.WebTraceListener,WCFApplicationLogging" />
</sharedListeners>
</system.diagnostics>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="E:\EnterPrise_Libary\Sample\rolling.log" rollFileExistsBehavior="Increment"
rollSizeKB="124" maxArchivedFiles="1200" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
Extended Properties: {dictionary({key} - {value}{newline})}"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings />
<client />
<diagnostics>
<messageLogging logEntireMessage="true"
logMalformedMessages="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"/>
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
20} WebTraceListener.cs
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging.ExtraInformation;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.EnterpriseLibrary.Logging.Filters;
using System.Diagnostics;
using System.Collections.Generic;
namespace WCFApplicationLogging
{
public class WebTraceListener : TraceListener
{
private LogWriter logWriter = null;
private TraceManager traceManager = null;
IDictionary
public WebTraceListener()
{
this.logWriter = EnterpriseLibraryContainer.Current.GetInstance
this.traceManager = EnterpriseLibraryContainer.Current.GetInstance
this.categories = this.logWriter.TraceSources;
}
public override void Write(string message)
{
this.logWriter.Write(message, "Avinash test");
}
public override void WriteLine(string message)
{
this.logWriter.Write(message, "Avinash test");
}
}
20 } WCF service
I have used Bolier plate code Given by Microsoft so it is default code.
Wednesday, January 26, 2011
Posting Information Using HttpWebRequest In WCF
Few days ago I have post Information Using HttpWebRequest To WCF I Will Share The code and Way To get Xml for Posting.
I Searched Net I was Not able to get better Example of Posting Xml Soap Envolpe to WCF.
So Let Start.
What I have Used is Vs2010
Get Soap XML
When You Run WCF Project u Will Get WCF Test Client.
You Will See WCF Test Client
2} When U Will Run Method You Will Get The Follwing Out Put
This is Normal Scenario
3} Know We Will Get Xml For Posting (When u Will Click XML Tab) then U Will See
Know U want Post Information
Copy Xml From Request
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService1/GetData</Action>
</s:Header>
<s:Body>
<GetData xmlns="http://tempuri.org/">
<value>2</value>
</GetData>
</s:Body>
</s:Envelope>
Know We Will Move To c# Code
public string CreatteSoapRequest(string strSoapBodyInfo)
{
string strSoapvalue =@"<?xml version=""1.0"" encoding=""utf-8""?><soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""><soap:Body>" + strSoapBodyInfo + "</soap:Body></soap:Envelope>";
return strSoapvalue;
}
public void PostDataGetData()
{
/// You Take care 2 Things 1 Soapaction and Other Soap Envolvpe
string strvalue = "1";
string MethodXml = @"<GetData xmlns=""http://tempuri.org/""><value>1</value></GetData>";
string soap = CreatteSoapRequest(MethodXml);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost:65371/Service1.svc");
req.Headers.Add("SOAPAction", "\"http://tempuri.org/IService1/GetData\"");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
using (Stream stm = req.GetRequestStream())
{
using (StreamWriter stmw = new StreamWriter(stm))
{
stmw.Write(soap);
}
}
WebResponse response = req.GetResponse();
byte[] result = null;
string strvalue = response.GetResponseStream().ToString();
Stream responseStream = response.GetResponseStream();
// TODO: Do whatever you need with the response
int byteCount = Convert.ToInt32(response.ContentLength);
using (BinaryReader reader = new BinaryReader(response.GetResponseStream()))
{
result = reader.ReadBytes(byteCount);
}
SaveStreamToFile(result, "D://GetData.txt");
}
/// This test Method Which I Have Created for Wrting text file on hardDisk
private void SaveStreamToFile(Byte[] stream, String fileName)
{
FileStream file = new FileStream(fileName, FileMode.Create);
file.Write(stream, 0, stream.Length);
file.Flush();
file.Close();
}
for Composite U can Find The data In Same Way..
Sample Xml String is Below .
string MethodXml = @"<GetDataUsingDataContract xmlns=""http://tempuri.org/""> <composite xmlns:d4p1=""http://schemas.datacontract.org/2004/07/PostDataUsingWCF"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><d4p1:BoolValue>true</d4p1:BoolValue><d4p1:StringValue>Avinash</d4p1:StringValue></composite></GetDataUsingDataContract>";
I Searched Net I was Not able to get better Example of Posting Xml Soap Envolpe to WCF.
So Let Start.
What I have Used is Vs2010
Get Soap XML
When You Run WCF Project u Will Get WCF Test Client.
You Will See WCF Test Client
2} When U Will Run Method You Will Get The Follwing Out Put
This is Normal Scenario
3} Know We Will Get Xml For Posting (When u Will Click XML Tab) then U Will See
Know U want Post Information
Copy Xml From Request
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService1/GetData</Action>
</s:Header>
<s:Body>
<GetData xmlns="http://tempuri.org/">
<value>2</value>
</GetData>
</s:Body>
</s:Envelope>
Know We Will Move To c# Code
public string CreatteSoapRequest(string strSoapBodyInfo)
{
string strSoapvalue =@"<?xml version=""1.0"" encoding=""utf-8""?><soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""><soap:Body>" + strSoapBodyInfo + "</soap:Body></soap:Envelope>";
return strSoapvalue;
}
public void PostDataGetData()
{
/// You Take care 2 Things 1 Soapaction and Other Soap Envolvpe
string strvalue = "1";
string MethodXml = @"<GetData xmlns=""http://tempuri.org/""><value>1</value></GetData>";
string soap = CreatteSoapRequest(MethodXml);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost:65371/Service1.svc");
req.Headers.Add("SOAPAction", "\"http://tempuri.org/IService1/GetData\"");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
using (Stream stm = req.GetRequestStream())
{
using (StreamWriter stmw = new StreamWriter(stm))
{
stmw.Write(soap);
}
}
WebResponse response = req.GetResponse();
byte[] result = null;
string strvalue = response.GetResponseStream().ToString();
Stream responseStream = response.GetResponseStream();
// TODO: Do whatever you need with the response
int byteCount = Convert.ToInt32(response.ContentLength);
using (BinaryReader reader = new BinaryReader(response.GetResponseStream()))
{
result = reader.ReadBytes(byteCount);
}
SaveStreamToFile(result, "D://GetData.txt");
}
/// This test Method Which I Have Created for Wrting text file on hardDisk
private void SaveStreamToFile(Byte[] stream, String fileName)
{
FileStream file = new FileStream(fileName, FileMode.Create);
file.Write(stream, 0, stream.Length);
file.Flush();
file.Close();
}
for Composite U can Find The data In Same Way..
Sample Xml String is Below .
string MethodXml = @"<GetDataUsingDataContract xmlns=""http://tempuri.org/""> <composite xmlns:d4p1=""http://schemas.datacontract.org/2004/07/PostDataUsingWCF"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><d4p1:BoolValue>true</d4p1:BoolValue><d4p1:StringValue>Avinash</d4p1:StringValue></composite></GetDataUsingDataContract>";
Subscribe to:
Posts (Atom)