简体   繁体   中英

Configuration of WCF Service using wsHttpBinding

I'm having trouble setting a WCF Service using wsHttpBinding and Https base address.

The real issue is when defining the mex, in the Client test WCF:

Error: Cannot obtain Metadata from https://localhost:8722/Design_Time_Addresses/_20180420_WcfServiceLibraryTest/Service1/mex If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.
For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455 .

The 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>

Reading SO and trying every things I found I have try a lot config. But none show a progress worth of mentioning. And look more like, I have no idea. What is the correct configuration to make the most basic Ws work(Compile + testable in SoapUi) with wsHttpBinding?

I think it's possibly because the mex bindingConfiguration="" is set to an empty string? Try removing this, or setting it to a Binding.

If the default mexHttpBinding doesn't work, try changing it to wsHttpBinding . Here is a sample Custom Secure Metadata Endpoint that might help. It says:

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.

The WCF Test client will need to be configured for the different binding, but I think it will configure itself automatically.

<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>

The mex endpoint is wrong. That is the reason for the issue. The following link has complete details regarding the same.

https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-publish-metadata-for-a-service-using-a-configuration-file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM