我在使用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中编译+可测试)的正确配置是什么?
答案 0 :(得分:1)
我认为可能是因为mex bindingConfiguration=""
设置为空字符串?
尝试删除它,或将其设置为绑定。
如果默认mexHttpBinding
不起作用,请尝试将其更改为wsHttpBinding
。以下是可能有用的示例Custom Secure Metadata Endpoint。它说:
在许多其他示例中,元数据端点使用默认的
mexHttpBinding
,这是不安全的。这里使用带有Message安全性的WSHttpBinding
来保护元数据。为了使元数据客户端能够检索此元数据,必须使用匹配的绑定对它们进行配置。
需要为不同的绑定配置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>
答案 1 :(得分:0)
mex端点错误。这就是问题的原因。以下链接包含相同的完整详细信息。