1

我这里有一些遗留代码,其中有一个 WCF 服务。

该服务由客户端通过生成的Proxy.cs 调用

我认为它应该很简单,并想通过使用 svcutil.exe 生成我自己的代理,但我得到了很多不同的错误,这取决于我尝试的内容(使用运行 exe 进行下载、使用程序集、使用 webconfig)。例如,svcutil 告诉我该服务可能不会发布元数据(在我看来这不是真的)。

网络配置有:

<serviceMetadata httpGetEnabled="true"/>

它具有多站点绑定

如何生成这样的代理?想要更改合约中的某些内容,然后生成当前版本的代理。

目前我没有服务参考,因为它在添加一个 svcutil 时会出现一些错误。

有任何想法吗?

-edit- 服务通过自托管服务发布,与 msdn 中 WCF 示例中的服务非常相似。有多个服务的端点,它们在 dll 中实现。

-edit 2- 这是自助托管服务的 app.config 我已经替换了一些名称,只是为了让它不那么特别。

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="PersonDataModelContainer" connectionString="metadata=res://*/PersonDataModel.csdl|res://*/PersonDataModel.ssdl|res://*/PersonDataModel.msl;provider=System.Data.SqlServerCe.3.5;provider connection string=&quot;Data Source=|DataDirectory|\PersonDatabase.sdf&quot;" providerName="System.Data.EntityClient"/>
  </connectionStrings>
  <system.serviceModel>
    <bindings>
      <netMsmqBinding>
        <binding name="TransactionalNoSecurity" durable="true" exactlyOnce="true" maxReceivedMessageSize="2147483647" maxRetryCycles="1" receiveRetryCount="20" retryCycleDelay="00:05:00">
          <security mode="None"></security>
        </binding>
      </netMsmqBinding>

      <basicHttpBinding>

        <binding name="TransportSecurity" openTimeout="00:10:00" closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </basicHttpBinding>

      <ws2007HttpBinding>

        <binding name="NoSecurity" transactionFlow="true" maxReceivedMessageSize="200000" openTimeout="00:10:00" closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00">
          <security mode="None"></security>
        </binding>

        <binding name="UNMessageSecurity" transactionFlow="true" openTimeout="00:10:00" closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00">
          <security mode="Message">
            <message clientCredentialType="UserName" establishSecurityContext="true"/>
          </security>
        </binding>

        <binding name="CertMessageSecurity" transactionFlow="true" openTimeout="00:10:00" closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00">
          <security mode="Message">
            <message clientCredentialType="Certificate" establishSecurityContext="true"/>
          </security>
        </binding>

        <binding name="DomainMessageSecurity" transactionFlow="true" openTimeout="00:10:00" closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00">
          <security mode="Message">
            <message clientCredentialType="Windows" establishSecurityContext="true"/>
          </security>
        </binding>

        <binding name="RM_NoSecurity" transactionFlow="true" openTimeout="00:10:00" closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00">
          <reliableSession enabled="true" ordered="false"/>
          <security mode="None"></security>
        </binding>
      </ws2007HttpBinding>

      <netTcpBinding>
        <binding name="NoSecurity" transactionFlow="true">
          <security mode="None"></security>
        </binding>


        <binding name="DomainMessageSecurity" transactionFlow="true" openTimeout="00:10:00" closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00">
          <security mode="Message">
            <message clientCredentialType="Windows"/>
          </security>
        </binding>

        <binding name="CertMessageSecurity" transactionFlow="true" openTimeout="00:10:00" closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00">
          <security mode="Message">
            <message clientCredentialType="Certificate"/>
          </security>
        </binding>
      </netTcpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior name="SimpleServiceBehavior">
          <serviceMetadata httpGetEnabled="True" policyVersion="Policy15"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <services>

      <service name="MessagePlatform.LoggingService.GeneralLoggingService" behaviorConfiguration="SimpleServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/"/>
          </baseAddresses>
        </host>
        <endpoint address="Logging" binding="basicHttpBinding" name="LoggingService" contract="MessagePlatform.LoggingService.Contracts.ILoggingService"/>

      </service>
      <service name="MessagePlatform.GatewayService.GeneralGatewayService" behaviorConfiguration="SimpleServiceBehavior">
          <host>
            <baseAddresses>
              <add baseAddress="http://localhost:8000/"/>
            </baseAddresses>
          </host>
          <endpoint address="gateway" binding="basicHttpBinding" name="GatewayService" contract="MessagePlatform.GatewayService.Contracts.IGatewayService"/>
          <endpoint address="gateway" binding="basicHttpBinding" name="Db2GatewayService" contract="MessagePlatform.GatewayService.Contracts.IDb2GatewayService"/>
          <endpoint address="gateway" binding="basicHttpBinding" name="Db1GatewayService" contract="MessagePlatform.GatewayService.Contracts.IDb1GatewayService"/>

          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

      </service>

    </services>
    <client>
      <endpoint name="LoggingServiceEP" address="http://localhost/Logging" binding="basicHttpBinding" contract="MessagePlatform.LoggingService.ILoggingService">        
      </endpoint>

      <endpoint name="GatewayServiceEP" address="http://localhost/gateway" binding="basicHttpBinding" contract="MessagePlatform.GatewayService.IGatewayService">
      </endpoint>

      <endpoint name="GatewayServiceDb2" address="http://localhost/gateway" binding="basicHttpBinding" contract="MessagePlatform.GatewayService.IDb2GatewayService">
      </endpoint>

      <endpoint name="GatewayServiceDb1" address="http://localhost/gateway" binding="basicHttpBinding" contract="MessagePlatform.GatewayService.IDb1GatewayService">
      </endpoint>

    </client>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
  </startup>
</configuration>
4

1 回答 1

2

您还需要启用 Metadata Exchange Endpoint,以便创建新代理:

<service name="MessagePlatform.GatewayService.GeneralGatewayService" behaviorConfiguration="SimpleServiceBehavior">
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost:8000/"/>
    </baseAddresses>
  </host>
  <endpoint address="gateway" binding="basicHttpBinding" name="GatewayService" contract="MessagePlatform.GatewayService.Contracts.IGatewayService"/>
  <endpoint address="gateway" binding="basicHttpBinding" name="Db2GatewayService" contract="MessagePlatform.GatewayService.Contracts.IDb2GatewayService"/>
  <endpoint address="gateway" binding="basicHttpBinding" name="Db1GatewayService" contract="MessagePlatform.GatewayService.Contracts.IDb1GatewayService"/>

  <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

</service>

并运行

svcutil http://localhost:8000/mex
于 2013-01-28T13:57:08.677 回答