web service etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
web service etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

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

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

Value cannot be null. Parameter name: name

add web reference ile web service eklenirken, veya web service çalıştırılırken, dbml'in güncel olmaması nedeniyle bulunamayan nesneler (stored procedure vb.) bu hataya neden olabiliyor.

web service - The test form is only available for requests from the local machine

<configuration>

<system.web>

<webServices>

<protocols>

<add name=”HttpGet”/>

<add name=”HttpPost”/>

</protocols>

</webServices>

</system.web>

</configuration>

linq to sql - Type 'http://microsoft.com/wsdl/types/:char' is not declared

web service char alan içeren bir objeyi döndüremiyor.

char alanı varchar'a çevirdiğim halde, dbml'de değişmiyor. elle değiştirmek gerekiyor.
aynı şekilde wsdl'de de elle değişiklikler gerekebilir.

web service - Cannot merge schemas with targetNamespace='http://tempuri.org/'. Several mismatched declarations were found: Schema item 'complexType' named 'Page'...

Cannot merge schemas with targetNamespace='http://tempuri.org/'. Several mismatched declarations were found: Schema item 'complexType' named 'Page' from namespace 'http://tempuri.org/'.

geçersiz:
[WebMethod]
public void Create(Page page, out string errors)
{
PageController controller = new PageController();
controller.Create(page, out errors);
}

geçerli:
[WebMethod]
public void Create(string title, out string errors)
{
PageController controller = new PageController();
var page = new Page();
page.Title = title;
controller.Create(page, out errors);
}

daha iyi bir çözüm:
[WebMethod]
public void Create(SerializableEntity page, out string errors)
{
_controller.Create(page.Entity, out errors);
}

Parametre olarak Page'i (yani complextype'ı) kabul etmiyor.

Not: LinqSqlSerialization.dll

web service - Use the MessageName property of the WebMethod custom attribute to specify unique message names for the methods

Step 1: Use diffrent MessageName attribute values.

public class MyWS : System.Web.Services.WebService
{
[WebMethod(MessageName = "GetItemById")]
public Item GetItem(int id)
{
...
}

[WebMethod(MessageName = "GetItemByUniqueTitle")]
public Item GetItem(string uniqueTitle)
{
...
}
}

Step 2: Set your webservice binding: ConformsTo = WsiProfiles.None

web service - linq to sql & web service

public class IntertechWS : System.Web.Services.WebService
{
[WebMethod]
public SerializableEntity<Page> GetPage(int id)
{
PageController ctrl = new PageController();
Page page = ctrl.GetPage(id);

SerializableEntity<Page> entity = new SerializableEntity<Page>(page);
return entity;

//IntertechDBDataContext db = new IntertechDBDataContext();
//var page = db.Pages.SingleOrDefault<Page, SerializableEntity<Page>>(p => p.PageID == id);
//return page;
}

[WebMethod]
public List<SerializableEntity<Page>> GetSubPages(int id, int langId)
{
PageController ctrl = new PageController();
return ctrl.GetSubPages(id, langId).ToList<Page, SerializableEntity<Page>>();

//IntertechDBDataContext db = new IntertechDBDataContext();
//var pages = db.Pages.ToList<Page, SerializableEntity<Page>>();
//return pages;
}
}


DTO - not only for web services

Usually developers think that DTO (Data Transfer Object) is something related to web services where data serialization is required to move data from one point of network to another. It is clear that in most cases there is no point to move complex data structures over network when client side needs this data in pretty simple form. That's why DTOs are created - they are simple, easily serializable and there is no data that client side doesn't need. But there are also other DTOs you may find useful.

User Interface DTOs

User Interface (UI) may also need some DTOs. By example, data bound controls try usually to save bounded data to their ViewState. But what happens when data source is list on some objects and not DataTable as we can usually see from beginner tutorials? DataTable is serializable and therefore it is easy to save DataTable to ViewState. But objects are often not marked as serializable and binding them to data bound controls may cause exceptions.

This problem can be solved using DTOs. We can create DTOs as flat objects that are serializable. They doesn't contain any child objects - only properties with their values. We can wrap source data to DTOs and bind list of these DTOs to our data bound controls.

Search criteria DTOs

In one of our current project we are using some DTOs to define search criterias. These DTOs are also flat ones because they store only ID-s of search conditions, string tokens and dates. There is one main search DTO and some internal search DTOs. This far we are happy with this solution because if we design those DTOs carefully they are very easy and convenient to use in client code.

Search sitemap DTOs

ASP.NET Futures has support for search engine sitemaps (follow this reference to take a look at the code examples). To let it create a search engine sitemap for products you must define class for products that has specific attributes required by sitemap generating system. This object is also simple DTO because it has no complex attributes.

I am sure that there are many more DTOs, these three were just examples of some additional DTOs besides DTOs we are using with web services. Okay, and as a last word - DTO is design pattern refered also to as Value Object in Sun.

http://weblogs.asp.net/gunnarpeipman/archive/2008/07/18/dto-not-only-for-web-services.aspx

search this blog (most likely not here)