consume WCF Soap servce in an add-in extension?

5271
4
02-06-2012 01:37 PM
CharlieRichman
New Contributor
Our test WCF service works just fine from a VS 2010 stand-alone Windows Form app but generates a run-time error whenever we try to instantiate an object via the generated proxy classes in a VS 2010 ArcGIS add-in project extension. 

In each case I added the WCF service as a new service reference.  The projects compile, and the Windows Forms app runs without error.  When I try to initialize an object to a new OPTrackingClient() in my add-in extension I get "Could not find default endpoint element that references contract OPTS.IOPTracking" 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."  I checked the relevant bits of the two app.config files and they appear to match: 

            <wsHttpBinding>
                <binding name="WSHttpBinding_IOPTracking" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://opnas01.op.dcgov.priv/optoolsservices/OPTracking.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IOPTracking"
                contract="OPTS.IOPTracking" name="WSHttpBinding_IOPTracking">
                <identity>
                    <servicePrincipalName value="host/opnas01.op.dcgov.priv" />
                </identity>
            </endpoint>
        </client>

Is there some other bit of configuration I need to do to allow ArcMap (and my extension) to tap this WCF service successfully?  Can ArcMap make use of this config info effectively, or do I need a different approach?

Charlie Richman
District of Columbia Office of Planning
0 Kudos
4 Replies
CharlieRichman
New Contributor
(Don't you hate answering your own questions?)

As I suspected, my code doesn't have access to the app.config file generated by the Visual Studio Add Service Reference tool -- we're seeing ArcMap's, not our own.

We can still use the proxy classes generated by that tool, but not the binding information (because it lives in the app.config file.)

Our workaround is to create our own binding and client reference in code, e.g.

...
using OpToolsAddin.opts; // the web reference added by VS 2010


namespace OpToolsAddin
{
    public class TestWCFService
    {
        public static OPTrackingClient ConfigureOPTrackingClientProxy()
        {
            // set up binding so we can get a new tracking client
            //  *** this is necessary because ArcMap can't see the binding info in our code's .config file ***
            WSHttpBinding binding = new WSHttpBinding();
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            EndpointAddress remoteAddress = new EndpointAddress("http://opnas01.op.dcgov.priv/optoolsservices/OPTracking.svc");
            OPTrackingClient client = new OPTrackingClient(binding, remoteAddress);
            return client;
        }

    }
}


Charlie Richman
District of Columbia Office of Planning
0 Kudos
zeshengcai
New Contributor
I have encountered the same problem. But I do not understand the solution you posted. Can you post the references you used to build the proxy class? Cause I can not find the classes like WSHttpBinding or EndpointAddress . My app.config file is attached

Zesheng
caizsheng@hotmail.com
0 Kudos
mohannainar2
New Contributor

Hi I am also facing the same issue , is that problem resolved ? . Please tell me how I need to proceed further.

0 Kudos
ErinBrimhall
Occasional Contributor II

Mohan,

Here is some potentially helpful info:

How to: Add a Reference to a Web Service‌  This will generate the proxy objects you need to invoke the web service from your client (i.e. ArcMap add-in)

Next, you need to decide how the endpoint binding information will be set on your proxy.  Two possible options here:

  • Allow the proxy's endpoint binding to be automatically set from configuration.  This will require you to copy the generated connection info from your add-in's app.config into the ArcMap config: C:\Program Files (x86)\ArcGIS\Desktop10.x\bin\ArcMap.exe.config

  • Manually set up the endpoint and binding objects in code (see whatCharlie Richman‌ did in his reply above).  This can involve the use of the WSHttpBinding‌ and EndpointAddress classes.  This option gives you full control but leaves a lot of room for errors.
0 Kudos