Thursday, February 5, 2009

Consuming WCF Service From Classic ASP

Consuming WCF services from classic ASP is described on several places, for instance http://msdn.microsoft.com/en-us/library/bb735856.aspx#_Toc156817372.

I ran into the "The maximum string content length quota (8192) has been exceeded"-exception, i.e. the message I try to send is larger than 8192 bytes.

Ok, just to add a binding configuration to allow larger messages. But I consume the WCF service from VB Script with a moniker, so where to define the binding configuration?

It took a while before I realised that, as classic ASP does not have a web.config, the binding configuration has to be in the machine.config.

Not so dynamic but an acceptable solution.

6 comments:

  1. When you made this change to the machine.config for the client side consumer of the WCF service, did you add both an endpoint setting and a binding configuration, or just a binding configuration?

    ReplyDelete
  2. I just added the binding configuration.
    The endpoint setting is not used when accessing the WCF service through the moniker (simulating a COM interface).

    An example in VbScript (where MyNetTcpBinding is defined in machine.config):

    Dim moniker: moniker="service:address=net.tcp://localhost:8731/MyService/SomeMethods, "
    moniker=moniker + "contract={AF23BEA6-8668-6999-AC69-4DEBA72AA8E3}, "
    moniker=moniker + "binding=MyNetTcpBinding, "
    moniker=moniker + "bindingNamespace=http://myservices.com"

    Dim wcfProxy : Set wcfProxy = GetObject(moniker)

    Dim result : result = wcfProxy.DoSomething()

    ReplyDelete
  3. Daniel Strickland01 October, 2010 23:28

    Anders, thank you for your hint. I've tried this a number of ways, but an still running into the 8192 char limit, and I must be overlooking something simple. I've tried changing the binding name in the moniker to what I've defined in the machine.config (netTcpLargeMessageBinding), but it always comes back with no supported interface found. I've made sure that I'm only defining that binding once, and not including it in the .config file for the WCF hosted service itself, only in the machine.config.

    So, I'm wondering if you see anything obviously wrong or have any other suggestions to getting that working.

    Right now, my moniker is configured as the following (which, I can confirm the service is working, and runs appropriately, as calls via ASP with this moniker are successful for calls that return less than 8192 bytes):

    addr = "service:mexAddress=net.tcp://localhost/Clients/LeadsMiddleware/MyWCF.svc/mex," & _
    "address=net.tcp://localhost/Clients/MyMiddleware/MyWCF.svc/," & _
    "contract=IMyData, contractNamespace=http://tempuri.org/," & _
    "binding=NetTcpBinding_IMyData, bindingNamespace=http://tempuri.org/"

    Then in machine.config, the bindings and behaviors are configured.





















    Lastly, in the .config file for the service (It's a WCF Library that's hosted in IIS via WAS), here are the settings for the service:

    ReplyDelete
  4. Daniel Strickland01 October, 2010 23:30

    Trying once more with the html chars url encoded:

    Then in machine.config, the bindings and behaviors are configured.

    <bindings>
    <netTcpBinding>
    <binding name="netTcpLargeMessageBinding" maxBufferPoolSize="524288"
    maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
    maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
    </netTcpBinding>
    <mexTcpBinding>
    <binding name="mexTcpLargeMessageBinding" />
    </mexTcpBinding>
    </bindings>
    <behaviors>
    <serviceBehaviors>
    <behavior name="MyWCF.MyDataBehavior">
    <serviceMetadata httpGetEnabled="false" />
    <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
    </serviceBehaviors>
    </behaviors>


    Lastly, in the .config file for the service (It's a WCF Library that's hosted in IIS via WAS), here are the settings for the service:

    <services>
    <service behaviorConfiguration="MyWCF.MyDataBehavior" name="MyWCF.MyData">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpLargeMessageBinding"
    contract="MyWCF.IMyData">
    <identity>
    <dns value="localhost" />
    </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="mexTcpLargeMessageBinding"
    contract="IMetadataExchange" />
    <host>
    <baseAddresses>
    <add baseAddress="net.tcp://localhost:808/Clients/MyMiddleware/" />
    </baseAddresses>
    </host>
    </service>
    </services>

    ReplyDelete
  5. David, I'm sorry for the late reply but I've been away from the office a few days.

    I notice that my post contain a copy and paste error. I hope it didn't mislead you too much.

    The correct moniker should be defined like this:
    Dim moniker: moniker="service:address=net.tcp://localhost:8731/MyService/SomeMethods, "
    moniker=moniker + "contract={AF23BEA6-8668-6999-AC69-4DEBA72AA8E3}, "
    moniker=moniker + "binding=netTcpBinding, "
    moniker=moniker + "bindingConfiguration=MyNetTcpBinding, "
    moniker=moniker + "bindingNamespace=http://myservices.com"

    Your configuration seems ok otherwise.

    ReplyDelete
  6. Daniel Strickland05 October, 2010 16:08

    Thanks Anders! I'll give it a try. I appreciate the help.

    ReplyDelete