A small tip for you..If you come across this error,The type or namespace name ‘DataContractAttribute’ could not be found (are you missing a using directive or an assembly reference?) make sure that you add the reference to dll System.Runtime.Serialization and refer the namespace.
Posts Tagged ‘WCF’
The type or namespace name ‘DataContractAttribute’ could not be found (are you missing a using directive or an assembly reference?)
Posted: August 28, 2011 in WCFTags: DataContractAttribute, WCF
Whoever comes from a soap service background always may have an assumption that for generating proxies you need to rely on svcutil.exe.If you think so,this assumption is wrong.You can create a proxy manually too.I am explaining here how you can do for a WCF service.
The proxy class derives from the class ClientBase<T> & ClientBase<T> accepts a single generic type parameter which is the service contract this proxy encapsulates. Say you have a servicecontract IVendorServices,then ClientBase<T> gets replaced with ClientBase<IVendorServices>.
[ServiceContract] public interface IVendorServices { [WebGet(UriTemplate = "v1/Ping")] [OperationContract] string Ping(); } public class VendorServices : IVendorServices { [Description("Service for Testing")] public string Ping() { return DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss:fffffffK"); } } public class VendorProxy : ClientBase<IVendorServices>, IVendorServices { public VendorProxy() { } #region IVendorServices Members public string Ping() { return Channel.Ping(); } #endregion }
After you write the proxy class,if you place mouse over the interface name,it will create the members of class automatically.The Channel property of ClientBase<T> is of the type of T parameter passed & if you write Channel.Ping(),it delegates the call to the method’s actual implementation & returns you the result.
Hope you got some idea on how it works 🙂
How can I create or edit the settings for WCF services in my web.config?
Posted: February 3, 2011 in Uncategorized, WCFTags: edit web.config for wcf, SvcConfigEditor.exe, WCF
The Configuration Editor Tool (SvcConfigEditor.exe) helps you to create and edit configuration settings WCF bindings, behaviors, services,diagnostics for wcfservices without having them modified manually.You can find the exe in the below path.
“C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\SvcConfigEditor.exe”
After you launch the Service Configuration Editor, you can use the File/Open menu to browse for the service or assembly you want to manage.
More about this,you can read from here
WCF client throws EndpointNotFoundException
Posted: January 16, 2011 in WCFTags: EndpointNotFoundException, New to WCF, Practical WCF, WCF, WCF client throws EndpointNotFoundException, windows service
Say,you have a WCF client that invokes a Windows Service.If you make changes to the Windows Service, before you call from client,you must first stop Windows Service and uninstall it. To stop the service, right-click the service in the SCM and select “Stop”.To uninstall the Windows Service type installutil /u bin\service.exe at the command prompt.
Note that if you stop the Windows Service and then run a client, an EndpointNotFoundException exception occurs when a client attempts to access the service.Make sure that your service is running before you make a call.
Cannot have two operations in the same contract with the same name
Posted: January 12, 2011 in Categories, WCFTags: WCF
Exception – Cannot have two operations in the same contract with the same name, methods GetDataForTeacher and GetDataForStudent in type WcfSample.IStock violate this rule. You can change the name of one of the operations by changing the method name or by using the Name property of OperationContractAttribute
When I got this exception while using same Name,was wondering what is the role of Name parameter,Methods are implemented with two different names & why is it throwing this exception for the below contract.
[ServiceContract]
public interface IStock
{
[OperationContract(Name ="GetData")]
string GetDataForTeacher(int value);
[OperationContract(Name ="GetData")]
string GetDataForStudent(int value);
}
First lesson learnt,do not use anything by simply copy pasting :)Understand the purpose & if it is required then only use it.
Now let me come to the point what does this Name property do?Name has to be specified when you need to override the element name in WSDL.ie to override the name of methods GetDataForTeacher & GetDataForStudent in wsdl.When you specify Name,now what has happend is it reads as two methods with name GetData.Ideally,Name should be specified only in cases where you have the same implementing method names(overloading scenario) as shown below.
[ServiceContract]
public interface IStock
{
[OperationContract(Name ="GetDataForTeacher")]
string GetData(int value);
[OperationContract(Name ="GetDataForStudent")]
string GetData(string value);
}