I have to use a SOAP web service provided via WSDL definition. After adding Service Reference it results in the following code for operations:
[System.ServiceModel.OperationContractAttribute(Action="http://provided.svc/changeBookingRequest", ReplyAction="http://provided.svc/changeBookingResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
[return: System.ServiceModel.MessageParameterAttribute(Name="return")]
Provided.Service.changeBookingResponse changeBooking(Provided.Service.changeBookingRequest request);
The problem is that I want to change signatures so they are capitalized (and change the object type from object
and response field from return
as they are both reserved keywords in C# and result in @object
and @result
scattered all across the project):
[System.ServiceModel.OperationContractAttribute(Action="http://provided.svc/changeBookingRequest", ReplyAction="http://provided.svc/changeBookingResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
[return: System.ServiceModel.MessageParameterAttribute(Name="return")]
Provided.Service.ChangeBookingResponse ChangeBooking(Provided.Service.ChangeBookingRequest request);
For that purpose I prepared a simple PowerShell script:
$env:WCF='C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools'
$env:CSC='C:\Windows\Microsoft.NET\Framework\v4.0.30319'
$env:Path="$env:WCF;$env:CSC"
svcutil /svcutilconfig:app.config /d:OutFolder `
/t:code https://*****/**Service?wsdl `
/serializable /reference:'C:\Users\Andrew\****\**.WsdlImport.dll'
app.config
has the following section:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
...
<client>
...
<metadata>
<wsdlImporters>
<extension type="***.WsdlImport.CapitalizeWsdlImporter, ***.WsdlImport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</wsdlImporters>
</metadata>
</client>
</system.serviceModel>
</configuration>
CapitalizeWsdlImporter
class implements IWsdlImportExtension
but all the relevant properties that I can hypothetically change are read-only. I was only able to change Contract name:
public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
{
ContractDescription contract = context.Contract;
contract.Name = "ET" + FirstCharToUpper(contract.Name);
}
I'll be very grateful for help!
P.S. Ha! While no one is giving reaction to my question, the problem I faced caused me to think much deeper of isolating those ugly classes and service calls in a single project and nothing further, which by now brought only the positive effects.