Search code examples
c#visual-studio-2010web-serviceswsdl

Trying to make C# client communicate with web service on localhost


I have an undocumented web service and I need to get the version of this web service by using client written in Visual C#. Problem is that I'm too much of a noob.

I have added the Service Reference in Visual Studio so I got a proxy file and the output.config file.

I get this row from VS to start a new instance of the class:

DentalScannerServiceClient client = new DentalScannerServiceClient();

So I put this in my console app:

DentalScannerServiceClient client = new DentalScannerServiceClient();
client.GetSoftwareVersion();

Get the error "No overload for method 'GetSoftwareVersion' takes 0 arguments". Intelisens tells me this when i start typing client.GetSoftwareVersion:

Status DentalScannerServiceClient.GetSoftwareVersion(out string version)

So I try this code:

    DentalScannerServiceClient client = new DentalScannerServiceClient();
    string oo;
    client.GetSoftwareVersion(out oo);

And then print the string but when I run the code I get this error:

"InvalidOperationException was unhandled" "Could not find default endpoint element that references contract 'IDentalScannerService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."

Any ideas how to solve this or where to start looking? I am thankful for any help. Maybe it is something simple. I little experience with C# as well.

app.config:

<?xml version="1.0"?>
<configuration>
<configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <section name="ThisIsTest.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    </sectionGroup>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><applicationSettings>
        <ThisIsTest.Properties.Settings>
            <setting name="ThisIsTest_localhost_DentalScannerService" serializeAs="String">
                <value>http://localhost:8731/DentalServiceLib/DentalScannerService/</value>
            </setting>
        </ThisIsTest.Properties.Settings>
    </applicationSettings>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8731/DentalServiceLib/DentalScannerService/"
                binding="basicHttpBinding" bindingConfiguration="BasicEndPoint"
                contract="Scanner.IDentalScannerService" name="BasicEndPoint" />
        </client>
    </system.serviceModel>
</configuration>

output.config (got this from wsdl.exe, just did Project->Add Existing Item to add it:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8731/DentalServiceLib/DentalScannerService/"
                binding="basicHttpBinding" bindingConfiguration="BasicEndPoint"
                contract="IDentalScannerService" name="BasicEndPoint" />
        </client>
    </system.serviceModel>
</configuration>

Solution

  • Since I could not get this method to work I did it another way:

    1. Use the .wsdl file generated by wsdl.exe in the SDK
    2. Downloaded soapUI and started a new project with the wsdl file as initial file
    3. soapUI created SOAP requests for all the objects in the web service
    4. Tested the different calls in soapUI and got response live
    5. Went into C# VS and made my console app first start the web service and then send simple SOAP requests using HttpWebRequest
    6. Bingo

    This method works surprisingly well!