3

I've recently noticed that using Service References(WCF) causes problems with plain old SOAP API's. I thought that the newer more improved approach was to use Service References because WCF is more flexible and modern. Can anyone detect how I can make this work with WCF in VS2013?

It is a simple console app trying to consume RxNav (free) api

URL: http://mor.nlm.nih.gov/axis/services/RxNormDBService

After adding a "Service Reference" to the solution I entered the following code:

Program.cs

static void Main(string[] args)
{
    var client = new RxNavAPI.DBManagerClient();

    try
    {
        var matches = client.getDrugs("aspirin");

        foreach (var conceptGroup in matches)
        {
            foreach (var concept in conceptGroup.rxConcept)
            {
                Console.WriteLine(String.Format("Name: {0}, Syn: {1}", concept.STR, concept.SY));
            }
        }

        client.close();
    }
    catch (TimeoutException ex)
    {
        Console.WriteLine("Timeout occurred while accessing RxNav API");
        Console.WriteLine(ex.Message);
        throw;
    }
}

App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="RxNormDBServiceSoapBinding" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://mor.nlm.nih.gov/axis/services/RxNormDBService"
                binding="basicHttpBinding" bindingConfiguration="RxNormDBServiceSoapBinding"
                contract="RxNavAPI.DBManager" name="RxNormDBService" />
        </client>
    </system.serviceModel>
</configuration>

One thing that I have noticed is when added as a Web Reference the client is called like:

var client = new RxNavAPI.DBManagerService();

while when using Service Reference it is like:

var client = new RxNavAPI.DBManagerClient();

EDIT: The error I am receiving is

System.InvalidOperationException : "RPC Message getProprietaryInformationRequest1 in operation getProprietaryInformation1 has an invalid body name getProprietaryInformation. It must be getProprietaryInformation1"

jdiaz
  • 7,354
  • 12
  • 42
  • 51
  • What issues are you seeing? If the only issue that you're seeing is the difference between `DBManagerService` and `DBManagerClient`? WCF appends `Client` to the services you add via add service reference. It's been a while since I've done ASMX, but perhaps ASMX added `Service` instead of `Client`. – Tim Feb 07 '14 at 18:17
  • In general, it should work, but there may, of course, be specific situations where it won't work. Create a separate question with specific details, and you'll probably get some good answers. – John Saunders Feb 07 '14 at 18:31
  • Tim/John I've added the error to the original post. I don't get this message when using a Web Reference. – jdiaz Feb 07 '14 at 19:06
  • John, I agree it general it should work but it doesn't. This isn't the only soap-based api that I've configured with Service Reference and it doesn't work. Almost everyone seems to say go with the older Web Reference as it's simpler and less error prone. – jdiaz Feb 07 '14 at 19:08

1 Answers1

0

Awesome! @John Saunders answering everywhere. This is the same issue noted over 5 years ago. WCF: Svcutil generates invalid client proxy, Apache AXIS Web Service, overload operations

Now I'm having the same issue and there is still no fix, only workarounds for this.

Community
  • 1
  • 1
valin077
  • 885
  • 1
  • 8
  • 17