简体   繁体   English

使“添加服务引用”>“发现”工作的最低配置

[英]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. 我已经测试了一些WCF + Windows服务并且在远程开发机器上作为Windows服务运行正常工作。 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). 为了调试,我尝试使用内置的“添加服务引用”来托管WCF(没有Windows服务),然后将其托管在visual studio中(不知道主机的调用方式)。

Anyways, I cannot get the Add Service Reference to Discover my services. 无论如何,我无法获得添加服务参考来发现我的服务。

Since I am using Windoes Services, I am using TCP stuff. 由于我使用的是Windoes服务,我使用的是TCP。 This are some things I have done, all in the winforms app that I am adding the service reference : 这是我已经完成的一些事情, 所有这些都在我添加服务引用的winforms应用程序中

Add Project > Properties > Debug > Command line arguments: /client:"WcfTestClient.exe" but the exe doesn't run. 添加项目>属性>调试>命令行参数:/client:“WTfTestClient.exe”但exe不运行。

And my App.Config 还有我的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. 附注 :ServiceOperation正在返回Microsoft.Synchronization.Data.xxx sutff,例如SyncContext。 I might have to add a reference in the Winforms? 我可能要在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. 项目文件本身例如* .csproj for C#项目必须包含用于WCF的ProjectTypeGuid,以便Visual Studio甚至开始检查项目的服务。

<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 . 可以在http://www.mztools.com/articles/2008/mz2008017.aspx找到更多GUID。 (Thanks mztools!) (谢谢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. WCF项目可以有多个服务,每个服务都需要在项目的App.Config中定义其配置。 Each service needs to have a different mex endpoint address. 每个服务都需要具有不同的mex端点地址。 The services can also share a single servicebehavior which has the serviceMetadata extension defined. 服务还可以共享单个servicebehavior,其中定义了serviceMetadata扩展。 Mex endpoint does not need behaviors or binding config. Mex端点不需要行为或绑定配置。 But remember to set mex endpoint contract to IMetadataExhchange. 但请记住将mex端点合约设置为IMetadataExhchange。

For TCP mex, the serviceMetadata > HttpGetEnabled must be set to false. 对于TCP mex,serviceMetadata> HttpGetEnabled必须设置为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 右键单击要在PC上托管的服务,然后右键单击并运行Debug> Start New Instance

Then go your other application (I assume same solution) and copy the URL it is running at. 然后去你的其他应用程序(我假设相同的解决方案)并复制它运行的URL。

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. 请告诉我这是不是别的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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