【问题标题】:WCF Service to talk to another WCF ServiceWCF 服务与另一个 WCF 服务通信
【发布时间】:2014-03-21 12:14:05
【问题描述】:

我创建了一个新的测试 WCF 应用程序。当我在 Visual Studio 中运行解决方案时,它可以使用带有 WCF 测试客户端的 Simple GetData 方法运行良好。但是,我现在想将服务引用添加到外部 WCF 服务,以便我可以从该 Web 服务与其对话。所以我 Service1 的界面现在看起来像:

public interface IService1 : MyExternalService

然后在我的服务类上,我有简单的 GetData,我可以点击实现接口,我看到创建的外部 Web 服务的所有方法:

     public class Service1 : IService1
        {
            public string GetData(int value)
            {
                return string.Format("You entered: {0}", value);
            }

            public string ExternalMethod1(string a, string b)
            {
                throw new NotImplementedException();
            }

//etc 

但是,如果我尝试使用 WCF 测试客户端运行它 - 我会收到以下错误消息 - Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.

在我包含外部服务参考后,它更新了我的 web.config 如下(注意一些实际的 url 已清理)

<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IExternalService">
          <security>
            <message clientCredentialType="Certificate" />
          </security>
        </binding>
        <binding name="WSHttpBinding_IExternalService1">
          <security>
            <message clientCredentialType="Certificate" negotiateServiceCredential="false"
              algorithmSuite="Basic128" establishSecurityContext="false" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://service.com/ExternalService/ExternalService.svc"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IExternalService"
        contract="ExternalService.IExternalService" name="WSHttpBinding_IExternalService">
        <identity>
          <dns value="service.com" />
        </identity>
      </endpoint>
      <endpoint address="http://service.com/ExternalService/ExternalService.svc/Java"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IExternalService1"
        contract="ExternalService.IExternalService" name="WSHttpBinding_IExternalService1">
        <identity>
          <dns value="service.com" />
        </identity>
      </endpoint>
    </client>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

【问题讨论】:

    标签: c# .net web-services wcf visual-studio


    【解决方案1】:

    您需要向第一个服务添加元数据交换端点

    <services>
       <service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
          <endpoint 
              address="http://localhost/MyService.svc" 
              binding="customBinding" bindingConfiguration="jsonpBinding" 
              behaviorConfiguration="MyService.MyService"
              contract="MyService.IMyService"/>
          <endpoint 
              address="mex" 
              binding="mexHttpBinding" 
              contract="IMetadataExchange"/>
       </service>
    </services>
    

    这个帖子似乎在讨论同样的问题WCF Test Client : Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata

    【讨论】:

    • 在网络配置的哪个部分?
    • ... 你应该已经在第一个服务中有这个部分
    • 您能否检查一下您是否在 .svc 文件中映射了正确的服务类和代码。您可以右键单击 Service*.svc 文件,然后选择“查看标记”以查看映射。
    • 你能不能也看看这个danderson.me/posts/…
    猜你喜欢
    • 2011-04-27
    • 1970-01-01
    • 2011-01-31
    • 2018-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多