Can you use optional parameters in a WCF service method?

<>

This question already has an answer here:

Answers


You can't. There are many restrictions on WCF regarding the method signatures; some restrictions are because of the host mechanism, and others because of the WSDL/MEX.

Despite the fact that WCF could potentially let you have default parameters in your service code and overloaded methods and many other things, when you host your service it might or not start, or it could start but might or not work. It's tricky.

What I've done to overcome this, is that I use nullable parameters wherever required, then on my client code I always have a service layer that access to my autogenerated client proxy; my service layer has all the overloads and optional params I want. Example (dirty code):

WCF service:

[OperationContract]
[FaultContract(typeof(MyCustomFault))]
List<InventoryPart> SelectMany(string partialPartNumber, string division, int? subDivision, bool? isActive);

Client Service Layer (not the autogenerated proxy, but one written by me)

public List<InventoryPart> GetParts(string partialPartNumber){
    return GetParts(partialPartNumber, null);
}

public List<InventoryPart> GetParts(string partialPartNumber, string division){
    return GetParts(partialPartNumber, division, null);
}

public List<InventoryPart> GetParts(string partialPartNumber, string division, int? subDivision){
    return GetParts(partialPartNumber, division, subDivision, null);
}

public List<InventoryPart> GetParts(string partialPartNumber, string division, int? subDivision, bool? isActive){
    // This method is the one that actually calls the client proxy channels and all.
}

My client app consumes the Client Service Layer

public void LoadPartNumbers(){
    var parts = ClientServiceLayer.GetParts(this.txtPartNumber.Text, null, (int) this.cboDivisions.SelectedItem );
}

Need Your Help

progressDialog in AsyncTask

android android-asynctask progressdialog

I'm trying to display a custom progressdialog while loading rss feed from http server, I made a hard search, but nothing helped me to do this, the only thing i know is that the solution should use

How can I rename class-names via Xml attributes?

c# xml xml-serialization

Suppose I have an XML-serializable class called Song: