微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 使用wsHttpBinding配置WCF服务

我在使用 wsHttpBinding和Https基地址设置WCF服务时遇到问题.

真正的问题是在客户端测试WCF中定义mex时:

错误:无法从中获取元数据
https://localhost:8722/Design_Time_Addresses/_20180420_WcfServiceLibraryTest/Service1/mex
如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布.
有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455中的MSDN文档.

App.config

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="NewBehavior0"> <!-- Error: Cannot optain Metadata -->
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>

            <behavior name="NewBehavior1"> <!-- Error: Cannot Find Cert -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceCredentials>
                <serviceCertificate  findValue="BadThumbprint" x509FindType="FindByThumbprint"  storeLocation="LocalMachine" storeName="My"/>
              </serviceCredentials>
            </behavior>

            <behavior name="NewBehavior2"> <!-- Error: Cannot optain Metadata -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceCredentials>
                <serviceCertificate  findValue="GoodThumbprint" x509FindType="FindByThumbprint"  storeLocation="LocalMachine" storeName="My"/>
              </serviceCredentials>
            </behavior>             
        </serviceBehaviors>
    </behaviors>

    <bindings>
        <wsHttpBinding>
            <binding name="wsHTTPBindingConf">
                <security mode="Transport">
                    <!--<message clientCredentialType="None" />-->
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>

    <services>
        <service behaviorConfiguration="NewBehavior0" name="_20180420_WcfServiceLibraryTest.Service1">
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHTTPBindingConf"
          name="WCFEndpoint" contract="_20180420_WcfServiceLibraryTest.IService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration=""
          name="mexEndPoint" contract="IMetadataExchange" />
            <host>
                <baseAddresses>
                    <add baseAddress="https://localhost:8722/Design_Time_Addresses/_20180420_WcfServiceLibraryTest/Service1/" />
                </baseAddresses>
            </host>
        </service>
    </services>
</system.serviceModel>

阅读SO并尝试我发现的每件事我尝试了很多配置.但没有一个显示出值得一提的进步.看起来更像,我不知道.
使用wsHttpBinding使最基本的W工作(在SoapUi中编译可测试)的正确配置是什么?

解决方法

我想这可能是因为mex bindingConfiguration =“”被设置为一个空字符串?
尝试删除它,或将其设置为绑定.

如果认的mexHttpBinding不起作用,请尝试将其更改为wsHttpBinding.这是一个可能有用的示例Custom Secure Metadata Endpoint.它说:

In many of the other samples,the Metadata endpoint uses the default mexHttpBinding,which is not secure. Here the Metadata is secured using WSHttpBinding with Message security. In order for Metadata clients to retrieve this Metadata,they must be configured with a matching binding.

需要为不同的绑定配置WCF测试客户端,但我认为它会自动配置自己.

<services>   
    <service name="Microsoft.ServiceModel.Samples.CalculatorService"  
             behaviorConfiguration="CalculatorServiceBehavior">  
     <!-- use base address provided by host -->  
     <endpoint address=""  
       binding="wsHttpBinding"  
       bindingConfiguration="Binding2"  
       contract="Microsoft.ServiceModel.Samples.ICalculator" />  
     <endpoint address="mex"  
       binding="wsHttpBinding"  
       bindingConfiguration="Binding1"  
       contract="IMetadataExchange" />  
     </service>  
 </services>  
 <bindings>  
   <wsHttpBinding>  
     <binding name="Binding1">  
       <security mode="Message">  
         <message clientCredentialType="Certificate" />  
       </security>  
     </binding>  
     <binding name="Binding2">  
       <reliableSession inactivityTimeout="00:01:00" enabled="true" />  
       <security mode="Message">  
         <message clientCredentialType="Certificate" />  
       </security>  
     </binding>  
   </wsHttpBinding>  
 </bindings>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐