Archive for the ‘Categories’ Category

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);

}

Advertisements

WCF useful links

Posted: December 5, 2010 in Categories, WCF
Tags: , ,

WCF Architecture Overview –
http://msdn.microsoft.com/en-us/library/aa480210.aspx

WCF Getting Started –
http://msdn.microsoft.com/en-us/library/ms734712.aspx

WCF 3.5 samples –
http://msdn.microsoft.com/en-us/library/ms751514.aspx

WCF 4.0 samples –
http://msdn.microsoft.com/library/dd483346(VS.100).aspx

Net endpoint blog (Blog by the .NET and AppFabric teams about WCF and WF development, deployment, and management) –

http://blogs.msdn.com/endpoint/

WCF REST Starter Kit –
http://www.asp.net/downloads/starter-kits/wcf-rest

WCF Forum –
http://social.msdn.microsoft.com/Forums/en/wcf/threads/

WCF Test Client – (WcfTestClient.exe)
http://msdn.microsoft.com/en-us/library/bb552364.aspx

(more…)

It’s been few months since I have started working with wcf services &  I have already talked about the same topic, way to test wcf services in linkedin.I thought this is the best place to share it once again.

For testing WCF services,there is a tool that microsoft ships with visual studio called WCF Test Client(WcfTestClient.exe)

This can be found at the following location

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\
More details on this can be found at

http://msdn.microsoft.com/en-us/library/bb552364.aspx .

A limitation I found with this is,only Soap endpoints which can expose metadata about itself (WSDL or Mex) can be invoked using this.

For Wcf REST services,One alternative you can try is to create the test client yourself in code using the ChannelFactory<T> class using the same contract used in the service(You will have to manually write a proxy as svcutil.exe do not support automatic proxy generation for REST services). Then use some network capture tool such as Fiddler (www.fiddlertool.com) to send requests to the service.

Though not all WCF tools are free,here are a few which you can try out.I have tried out SOAP Ui & SOA Cleaner for my services & seems to be good.

SoapUI can be found at : http://sourceforge.net/projects/soapui/files/

SOA Cleaner can be found at: http://xyrow.com/Home/Free

WCFStorm can be found at: http://www.wcfstorm.com/wcf/wcfstorm-lite.aspx 

One more useful way for developers to unit test WCF methods is to right click & generate test method.More details on this is available here

http://msdn.microsoft.com/en-us/library/ms182524(v=VS.90).aspx

Hope you find this information useful.If you have come across any other ways to test WCF services,please share.