简体   繁体   中英

Minimum configuration to make “Add Service Reference > Discover” work

I have already a few WCF + Windows Service tested and working correctly as run as a Windows Service on remote dev machines. Except for one.

In order to debug, I tried to host the WCF (without the Windows Service) using the built-in "Add Service Reference" and then hosting it in visual studio (don't know what the host is called).

Anyways, I cannot get the Add Service Reference to Discover my services.

Since I am using Windoes Services, I am using TCP stuff. This are some things I have done, all in the winforms app that I am adding the service reference :

Add Project > Properties > Debug > Command line arguments: /client:"WcfTestClient.exe" but the exe doesn't run.

And my App.Config

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <client>
      <endpoint address="net.tcp://localhost:32279/SYNC" binding="netTcpBinding"
        bindingConfiguration="tcpSyncBindingConfig" contract="Company.Data.Sync.ILocalCacheSyncContract"
        name="tcpSyncClientEP" />
    </client>
    <bindings>
      <netTcpBinding>
        <binding name="tcpSyncBindingConfig" maxReceivedMessageSize="6553600" />
      </netTcpBinding>
      <mexTcpBinding>
        <binding name="tcpMexBindingConfig" />
      </mexTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="svcBehavior" name="Company.Data.Sync.Services.LocalCacheSyncService">
        <endpoint address="net.tcp://localhost:32279/Sync" binding="netTcpBinding"
          bindingConfiguration="tcpSyncBindingConfig" name="tcpSyncListenEP"
          contract="Company.Data.Sync.Services.ILocalCacheSyncContract" />
        <endpoint address="net.tcp://localhost:32279/Sync/mex" binding="mexTcpBinding"
          bindingConfiguration="tcpMexBindingConfig" name="tcpMexEP" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="svcBehavior">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

Side note : the ServiceOperation are returning Microsoft.Synchronization.Data.xxx sutff for example SyncContext. I might have to add a reference in the Winforms? Or will the "Add Service Reference" add them for me? The service and contracts are generated by the Local Database Cache template. perhaps not related to the problem.

After posting, I continued to look for answers and this is what I experimented to be working:

The project file itself eg *.csproj for C# project must contain the ProjectTypeGuid for WCF for Visual Studio to even start checking the project for Services.

<ProjectTypeGuids>{3D9AD99F-2412-4246-B90B-4EAA41C64699};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

More GUIDs can be found at http://www.mztools.com/articles/2008/mz2008017.aspx . (Thanks mztools!)

The WCF project can have multiple services, and each of them needs to to have their config defined in the project's App.Config. Each service needs to have a different mex endpoint address. The services can also share a single servicebehavior which has the serviceMetadata extension defined. Mex endpoint does not need behaviors or binding config. But remember to set mex endpoint contract to IMetadataExhchange.

For TCP mex, the serviceMetadata > HttpGetEnabled must be set to false.

I believe this is the minimum settings.

Right click on the service you wish to host on your PC, then right click and go Debug > Start New Instance

Then go your other application (I assume same solution) and copy the URL it is running at.

Then you can start that one with the same method above and debug both projects on your local machine.

I assume this is what you are trying to do. Please let me know if it was something else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM