wsdl 未显示 XML-WCF

wsdl not showing XML-WCF

调用服务时 url https://example.com/TestService.svc 我得到了以下 2 个 URL,但是当我尝试单击 WSDL 时它不起作用。

WSDL URL

http://example.com/TestService.svc?wsdl -- 不工作

http://example.com/TestService.svc?singleWsdl -- 不工作

手动将 http 更改为 https

https://example.com/TestService.svc?wsdl -- 正在工作

https://example.com/TestService.svc?singleWsdl -- 正在工作

客户端配置

  <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</client>
<behaviors>
  <serviceBehaviors>
    <clear/>
    <behavior>          
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>          
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />

主要服务配置

<system.serviceModel>    
<behaviors>
  <serviceBehaviors>
    <clear />
    <behavior>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0">
  <serviceActivations>
    <clear />        
    <add factory="DataServicesHost.UnityServiceHostFactory" relativeAddress="TestService.svc" service="TestService.Service" />
  </serviceActivations>
</serviceHostingEnvironment>     

服务消费

var customHeader = new MessageHeader<Security>(security);
            var tempHeader = customHeader.GetUntypedHeader("Security", "http://tempuri.org/");

            var client = new ServiceClient();

            using (var scope = new OperationContextScope(client.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(tempHeader);
                objDataRequest = client.DataRequest("test");

            }

从上面的配置,我们可以推断出它属于客户端。但是,WCF 服务的 WSDL 功能是在服务器端设置的。它由 ServiceMetadata 部分控制。

<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>  

因此,如果我们想要让WSDL特性的HTTP协议工作,我们需要在服务器端启用它并在服务部分应用服务行为(端点应该在service 部分而不是 client 部分)。

<system.serviceModel>
    <services>
      <service name="WcfService3.Service1" behaviorConfiguration="sb">
        <endpoint address="" binding="basicHttpBinding" contract="WcfService3.IService1"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="sb">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
</behaviors>

如果有什么我可以帮忙的,请随时告诉我。