Search code examples
wcfmodel-view-controllerinterfaceweb-reference

how do I use my web reference in MVC?


greeting folks, I need to reference an external service in my MVC app.

I'm using this service to validate an authentication token that one of our clients has requested we use.

I'm porting an older project to MVC. I added a web reference.

The config was generated like so:

<system.serviceModel>
<bindings>
    <basicHttpBinding>
        <binding name="ExternalServicesSoap" 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://myapps.test.com/ExternalServices/ExternalServices.asmx"
        binding="basicHttpBinding" bindingConfiguration="ExternalServicesSoap"
        contract="AssertionService.ExternalServicesSoap" name="ExternalServicesSoap" />
</client>

In the older ASP.NET world, I could do the following on the specific service I am referencing, using the Assertion object defined in the external service reference.

        var service = new ExternalServices();
        Assertion assertion = service.Validate(Id);
        if(assertion.Valid){}

This doesn't seem to be the exact case in the MVC project. I seem to be working with WCF. I'm not sure if I'm approaching this properly in the MVC world.

All I have to work with is an ExternalServiesSoap interface or an ExternalServicesSoapChannel interface. None of which return an Assertion object like in the ASP.Net world. They both have the Validate method but return a ValidateAssertionResponse. The response object doesn't have any useful properties; just a response body. The Assertion class is still accessible but it doesn't seem to be returned by any of the interface methods.

Can anyone help me with how to properly use one of these interfaces?

thanks


Solution

  • Rather than adding a Service Reference, add a Web Reference. Right click on your project, select "Add Service Reference...". In the Add Service Reference dialog, click "Advanced", then click "Add Web Reference". This will generate a proxy that is appropriate for use with ASMX based services.