.NET Framework Bookmark and Share   
 index > Windows Communication Foundation > Create own client importer
 

Create own client importer

Hi,

when I add a service reference, Visual Studio creates the file 'Reference.cs'. Visual Studio implements the functions of a WCF service with following code:

public void <Functionname> {
return base.Channel.<Functionname>();
}

Now my question. Is it possible that the importer create following code automatically?

public void <Functionname> {
try
{
return base.Channel.<Functionname>();
}
catch (FaultException ex)
{
// Do anything
throw new MyException();
}
}

Regards
Marco La Tona

mlatona
Is GetDSRequest a [MessageContract] class with no members? If so, then it's equivalent to a parameterless method. I assume that GetDSResponseGetDSResult is also a [MessageContract] class with a DataSet parameter. There area fewtransformations that the Add Service Reference dialog (or svcutil.exe) does to "clean-up" the generated code, but they shouldn't affect the semantics of the type: it will still be usable as a way to send requests to the service.
Carlos Figueira
You won't be able to change the importer used by the "Add Service Reference" dialog, but you can create your own. Take a look at my post at thread http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/14100bbb-9a73-4bcc-b513-088bb2e5ec65, and you'll see a way to do that. After having the code in memory (CodeDom), you can traverse it andchange the function you need.
Carlos Figueira
Hi,

thank you for your answer. Now I can change the functions. But codedom produce incorrect code, when I add a function who returns a dataset.
I added following function to the service in your sample:

[OperationContract]
System.Data.DataSet GetDS();

Hope, you can help me.


Regards
Marco

mlatona
What is the problem with the code produced by CodeDom? That function seems ok by me...
Carlos Figueira
CodeDom generate following code for the function 'GetDS':

[System.ComponentModel.

EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]

GetDSResponse ITest.GetDS(GetDSRequest request) {

return base.Channel.GetDS(request);

}

public GetDSResponseGetDSResult GetDS() {

GetDSRequest inValue = new GetDSRequest();

GetDSResponse retVal = ((ITest)(this)).GetDS(inValue);

return retVal.GetDSResult;

}



When I create the service reference in VisualStudio, following code is generated for the function 'GetDS':

publicSystem.Data.DataSet GetDS() {

return base.Channel.GetDS();

}


Regards
Marco

mlatona

Does the function created by CodeDom work? It's possible that the ASR dialog does some optimization (i.e., for a parameterless method), but if those two functions are equivalent, then it shouldn't be an issue, right?

Carlos Figueira
I believe, the reason is the return type 'System.Data.DataSet' and not a parameterless method.
mlatona
Is GetDSRequest a [MessageContract] class with no members? If so, then it's equivalent to a parameterless method. I assume that GetDSResponseGetDSResult is also a [MessageContract] class with a DataSet parameter. There area fewtransformations that the Add Service Reference dialog (or svcutil.exe) does to "clean-up" the generated code, but they shouldn't affect the semantics of the type: it will still be usable as a way to send requests to the service.
Carlos Figueira

You can use google to search for other answers

Custom Search

More Threads

• WCF as a Windows Service
• DataMember Attribute declaration - On Member Variable or Property?
• calling problem (timeout)
• How to get the userName ?
• Calling WCF Sevice from .Net 2.0 Client
• catch SoapException in WCF
• WCF Callback and IsOneWay
• Error while displaying binary data from database ?
• Is there an answer that is not "wait for version 3.5"?
• WCF and ALSB common authentication without compatibility?