1

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.

berezovskyi
  • 3,133
  • 2
  • 25
  • 30
  • 1
    I'm looking for a solution to the *exact* same problem; I'm consuming a SOAP web service with wildly different and inconsistent naming conventions; I was hoping for the sake sanity to alias/map the type/method names on generation. http://stackoverflow.com/questions/22097706/auto-alias-generated-soap-proxies – Dan Lugg Mar 03 '14 at 16:26

0 Answers0