Is there a way to pass an optional parameter to a webservice, instead of having to overload the method?
If the webservice user is accessing the webservice directly, I want to do ActionA, if the user is accessing the webservice through my web interface, I want to do ActionA + ActionB.
no, you can't really have optional params for a service.
Even if an input parameter for a Web
service method is optional, you must
still include it and set the parameter
value to null
Supplying Web Service Method Arguments
So, its optional to a degree, that you dont have to supply a value, but you're still going to have to write null instead. Overloading is the 'normal' way to do this.
Related
I make my windows communication service parameter optional (in Operation Contract), but on the client when I dont want to pass optional parameter, error happens and requires this parameter. How can I fix it?
In my services all the methods except certain mandatory parameters and all the input parameters are encapsulated inside message contract.
Right now, we are validating the input in each and every service method, Its like duplicating validation logic in all the service methods. Is there any way I can move all these validation to common place and more over I don't want my service method to be executed as the input is not valid.
Appreciate your suggestions.
Yes, you can use FluentValidator for each MessageContract request.
You can write the commom validator for the request which have common validation rules.
Ex: If you want the validate employee profile in both CreateEmployeeRequest, UpdateEmployeeRequest then you can write the commom validator for Employee Profile (EmployeeProfileValidator) and make use of this validator in Create & Update Employee request validators..
Enterprise Library Validation Application Block has a module for Integration with WCF.
It implements input validation as a WCF parameter inspector. Your method will never be called if it the parameters fail validation.
Hello I am very new to WCF Services kindly excuse me for wrong terminology. I need to display all the methods in a list and when the method is selected I need to show the parameters so the user can enter the parameter value like id and name so that we can invoke the service and compare the result with expected and actual result.
Note: the user will only provide the WSDL URL, and from there I can generate a dynamic proxy because our services usually change using (http://blogs.msdn.com/b/vipulmodi/archive/2006/11/16/dynamic-programming-with-wcf.aspx).
How do I get the operation and parameter types so that we can generate client and invoke service with the parameters. Just want to display methods get the values for parameters from user and invoke the service in a C# windows application.
My requirement is, i have one WCF service with a method returning some integer value, this value i want to be used by another WCF service, but do not know how like as we used to pass value from one page to another page using sessions or query strings etc.
Thanks in advance
If you use the wcf-services in the same process you could just use static variables to transfer the values but I would advise to do so.
I would:
Refactor the behavior of both wcf-services into seperate classes (or even assemblies)
call the refactored methods from both services
This way you have a clean "seperation of concern" and can use the methods to generate your integer value without any pain.
I have an object I pass to a WCF service. Then on the server, the service modifies some properties of the object, and returns an int.
On the client side, after the service is called, the changes made to the objects' properties are not there.
My unit tests work fine. But when run over services, the problem occurs.
Any ideas on how to fix this?
When you pass something over the service boundary it's being passed by value not by reference so any changes made on the server will not propagate to the object you passed from the client. So you would want to return the modified object back to the client. If you also need to return the int you can create a wrapper class that can contain both the int and the changed object.
#jodogger, maybe I'm missing something but if the service returns an int, it certainly won't change your object.
The problem is that your object never actually makes the round trip to the server. Because of the disconnected nature of WCF, you must pass values byval and not byref.
If you must change values in the WCF service, you'll need to do something like this:
myObject = WCFService.MethodName(myObject);
That isn't actually the same object coming back, but you'll be clobbering your old object with the new values of that object.
Please note that the object being returned will need to be created by you in the DataContract section of the interface as well as the implementation itself.