Notes about WCF

A data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged.

Data contract can be explicit or implicit. Simple type such as int, string etc has an implicit data contract. User defined object are explicit or Complex type, for which you have to define a Data contract using [DataContract] and [DataMember] attribute.



Windows Communication Foundation (WCF) uses a serialization engine called the Data Contract Serializer by default to serialize and deserialize data (convert it to and from XML). All .NET Framework primitive types, such as integers and strings, as well as certain types treated as primitives, such as DateTime and XmlElement, can be serialized with no other preparation and are considered as having default data contracts. Many .NET Framework types also have existing data contracts. For a full list of serializable types, see Types Supported by the Data Contract Serializer.

New complex types that you create must have a data contract defined for them to be serializable. By default, the DataContractSerializer infers the data contract and serializes all publicly visible types. All public read/write properties and fields of the type are serialized. You can opt out members from serialization by using the IgnoreDataMemberAttribute. You can also explicitly create a data contract by using DataContractAttribute and DataMemberAttribute attributes. This is normally done by applying the DataContractAttribute attribute to the type. This attribute can be applied to classes, structures, and enumerations. The DataMemberAttribute attribute must then be applied to each member of the data contract type to indicate that it is a data member, that is, it should be serialized. For more information, see Serializable Types.


http://www.dotnetspider.com/forum/287974-What-DataContract-WCF.aspx

Wcf Linq Serialization Error

An error occurred while receiving the HTTP response to http://localhost:8732/Design_Time_Addresses/WcfServiceLibraryTest/GenreService/.
This could be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down).
See server logs for more details.

There was an error while trying to serialize parameter http://tempuri.org/:ListGenresResult.
The InnerException message was 'Object graph for type 'System.Data.Linq.EntitySet`1[[DataLayer.Musician, DataLayer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' contains cycles and cannot be serialized if reference tracking is disabled.'.

Solution:
Serialization Mode : Unidirectional (dbml file)

WCF Logging:
http://msdn.microsoft.com/en-us/library/ms732009.aspx
http://msdn.microsoft.com/en-us/library/ms730064.aspx

Smtp error - STARTTLS

SMTP sunucusu güvenli bir bağlantı gerektiriyor veya istemcinin kimliği doğrulanmadı. Sunucu yanıtı şöyleydi: 5.7.0 Must issue a STARTTLS command first ...

Solution:

smtpClient.EnableSsl = true;

http://social.msdn.microsoft.com/Forums/tr-TR/aspnettr/thread/3e00e300-ea1e-41be-b2c1-b64e93aab60f/

sql cache dependency

aspnet_regsql.exe –S “.\yukon” –U “sa” –P “1” –d “CacheDepDemo” –ed
aspnet_regsql.exe –S “.\yukon” –U “sa” –P “1” –d “CacheDepDemo” –t “Ogrenciler” -et

Sample:

C:\Windows\Microsoft.NET\Framework\v2.0.50727>aspnet_regsql.exe -S localhost -E
-ed -d Yasatay -et -t MevzuatDetay
Enabling the database for SQL cache dependency.
.
Finished.
Enabling the table for SQL cache dependency.
Finished.

http://stackoverflow.com/questions/4379106/configuring-sqlcachedependency-with-aspnet-regsql

blog html code editor

http://www.simplebits.com/cgi-bin/simplecode.pl

internet explorer 7 and 8 updatepanel rendering error


Örneğin aşağıdaki gibi bir kullanım IE7 ve IE8’de hataya (UpdatePanel’in çalışmamasına) neden oluyor:

<table>
<tr>
<td>
...
</td>
</tr>
<asp:UpdatePanel …>

</asp:UpdatePanel …>
<tr>
<td>
...
</td>
</tr>
</table>

Yukarıdaki örnekte UpdatePanel uygun olmayan yerde bulunuyor. Şu hale çevirince düzeliyor:

<table>
<tr>
<td>
...
</td>
</tr>
</table>
<asp:UpdatePanel …>

</asp:UpdatePanel …>
<table>
<tr>
<td>
...
</td>
</tr>
</table>

consuming web service using webrequest

public const string WebServiceUrl = "https://xxx.xxx.com.tr/server/cms";
const string methodName = "PR_SWEP_URT_OTO_WS_KASKO_TEKLIF_POLICELENDIR";

doc.LoadXml(xmlRequest);
var req = (HttpWebRequest)WebRequest.Create(Constants.WebServiceUrl);
req.Headers.Add("SOAPAction", Constants.WebServiceUrl + "/" + methodName);
req.Headers.Add("Operation", methodName);
req.Headers.Add("Style", "RPC");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
var stream = req.GetRequestStream();
doc.Save(stream);
stream.Close();


public const string WebServiceUrl = "http://xx.xx.xxx.xxx:xxxx/PolServis";
const string methodName = "getKaskoPolice";

doc.LoadXml(xmlRequest);
var req = (HttpWebRequest)WebRequest.Create(Constants.WebServiceUrl + "/services/KaskoPoliceServis?wsdl");
req.Headers.Add("SOAPAction", Constants.WebServiceUrl + "/" + methodName);
req.Headers.Add("Operation", methodName);
req.Headers.Add("Style", "RPC");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
var stream = req.GetRequestStream();
doc.Save(stream);
stream.Close();

java.lang.NumberFormatException HTTP Error 500 Internal server error

AracBedeli 29750,00 formatında gönderildiğinde şu satırda hata oluşuyor:

var webResponse = req.GetResponse();

HTTP Error 500 Internal server error hatası dönüyor.
Ama SoapUI'da hatanın nedeni görülebiliyor:

soapenv:Server.userException java.lang.NumberFormatException: Not a valid char constructor input: 29750,00

Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator

code:
var cpList2 = (from customerProduct in _context.customer_products
join controlPolice in controlPolices
on customerProduct.sales_ID equals controlPolice.sales_ID
where customerProduct.yenileme_no == controlPolice.yenileme_no
&& customerProduct.zeyil_no == controlPolice.zeyil_no
select customerProduct);

error:
Local sequence cannot be used in LINQ to SQL implementation of query
operators except the Contains() operator

solution:
var cpList = (from controlPolicy in controlPolicies
join customerProduct in _context.customer_products
on controlPolicy.sales_ID equals customerProduct.sales_ID
where controlPolicy.yenileme_no == customerProduct.yenileme_no
&& controlPolicy.zeyil_no == customerProduct.zeyil_no
select customerProduct);

source:
http://stackoverflow.com/questions/5936301/local-sequence-cannot-be-used-in-linq-to-sql-implementations-of-query-operators-e

How to enumerate an enum?

How to enumerate an enum?

public static class EnumExtensions
{
///


/// Gets all items for an enum value.
///

///
/// The value. ///
public static IEnumerable GetAllItems(this Enum value)
{
foreach (object item in Enum.GetValues(typeof(T)))
{
yield return (T)item;
}
}

///
/// Gets all items for an enum type.
///

///
/// The value. ///
public static IEnumerable GetAllItems() where T : struct
{
foreach (object item in Enum.GetValues(typeof(T)))
{
yield return (T)item;
}
}

///
/// Gets all combined items from an enum value.
///

///
/// The value. ///
///
/// Displays ValueA and ValueB.
///
/// EnumExample dummy = EnumExample.Combi;
/// foreach (var item in dummy.GetAllSelectedItems())
/// {
/// Console.WriteLine(item);
/// }
///

///

public static IEnumerable GetAllSelectedItems(this Enum value)
{
int valueAsInt = Convert.ToInt32(value, CultureInfo.InvariantCulture);

foreach (object item in Enum.GetValues(typeof(T)))
{
int itemAsInt = Convert.ToInt32(item, CultureInfo.InvariantCulture);

if (itemAsInt == (valueAsInt & itemAsInt))
{
yield return (T)item;
}
}
}

///
/// Determines whether the enum value contains a specific value.
///

/// The value. /// The request. ///
/// true if value contains the specified value; otherwise, false.
///

///
///
/// EnumExample dummy = EnumExample.Combi;
/// if (dummy.Contains(EnumExample.ValueA))
/// {
/// Console.WriteLine("dummy contains EnumExample.ValueA");
/// }
///

///

public static bool Contains(this Enum value, T request)
{
int valueAsInt = Convert.ToInt32(value, CultureInfo.InvariantCulture);
int requestAsInt = Convert.ToInt32(request, CultureInfo.InvariantCulture);

if (requestAsInt == (valueAsInt & requestAsInt))
{
return true;
}

return false;
}
}

The enum itself must be decorated with the FlagsAttribute

[Flags]
public enum EnumExample
{
ValueA = 1,
ValueB = 2,
ValueC = 4,
ValueD = 8,
Combi = ValueA | ValueB
}

http://stackoverflow.com/questions/105372/c-how-to-enumerate-an-enum

search this blog (most likely not here)