Answered by:
Adding/Calling WCF Reference

Question
-
User-2017823710 posted
Hi,
WCF Service: TestService\TestService.svc
WCF Method: Public String GetDetails(String Input)
Calling Service: I am adding the TestService.svc and I create a proxy object of ITestService. However I am not able to call GetDetails() using the proxy object and pass the string parameter. Instead Iam forced to create a ITestServiceInput object and pass the "Input" and also the output is not coming as string but as ITestServiceOutput.
Why am I not able to just pass a normal string and get a string returned as output? Please let me know if I am doing something wrong.
Thanks!!
Sid
Sunday, October 13, 2013 9:03 PM
Answers
-
User-488622176 posted
Did you follow the steps as shown here : http://www.codeproject.com/Articles/42643/Creating-and-Consuming-Your-First-WCF-Service
When passing/getting native .NET objects you do not need any datacontracts. Only mark the service methods as "OperationContract" and the service as ServiceContract. That should do the trick.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, October 14, 2013 5:09 AM -
User260886948 posted
Hi,
According to your description, I have created the following example, please try to refer to:
ITestService.cs:
[ServiceContract] public interface ITestService { [OperationContract] String GetDetails(String Input); }
TestService.svc.cs:public class TestService : ITestService { public String GetDetails(String Input) { return Input; } }
After running it in the browser, then we can call this TestService in the client as below:
class Program { static void Main(string[] args) { ServiceReference1.TestServiceClient client = new ServiceReference1.TestServiceClient(); string str = client.GetDetails("Good Work"); Console.WriteLine(str); Console.ReadLine(); } }
If you have any other problem, please let me know in your free time.
Best Regards,
Amy Peng
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, October 15, 2013 4:57 AM
All replies
-
User-1392847221 posted
Hi,
Are you using data contract ?
Please don't use it make it normal. I hope it will resolve your problem.
Sunday, October 13, 2013 11:07 PM -
User-488622176 posted
Did you follow the steps as shown here : http://www.codeproject.com/Articles/42643/Creating-and-Consuming-Your-First-WCF-Service
When passing/getting native .NET objects you do not need any datacontracts. Only mark the service methods as "OperationContract" and the service as ServiceContract. That should do the trick.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, October 14, 2013 5:09 AM -
User260886948 posted
Hi,
According to your description, I have created the following example, please try to refer to:
ITestService.cs:
[ServiceContract] public interface ITestService { [OperationContract] String GetDetails(String Input); }
TestService.svc.cs:public class TestService : ITestService { public String GetDetails(String Input) { return Input; } }
After running it in the browser, then we can call this TestService in the client as below:
class Program { static void Main(string[] args) { ServiceReference1.TestServiceClient client = new ServiceReference1.TestServiceClient(); string str = client.GetDetails("Good Work"); Console.WriteLine(str); Console.ReadLine(); } }
If you have any other problem, please let me know in your free time.
Best Regards,
Amy Peng
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, October 15, 2013 4:57 AM