Web services 如何配置WCF服务以同时使用HTTP和HTTPS

Web services 如何配置WCF服务以同时使用HTTP和HTTPS,web-services,wcf,service-model,Web Services,Wcf,Service Model,Iam正在尝试配置一个服务,以便从silverlight 4应用程序通过https和http进行访问。我可以通过https访问服务,但不能通过http访问。我已经在网上做了一些研究,但似乎没有得到正确的配置 下面是我的web.config文件中的当前设置。 <system.serviceModel> <bindings> <customBinding> <binding name="MyhttpsBind

Iam正在尝试配置一个服务,以便从silverlight 4应用程序通过https和http进行访问。我可以通过https访问服务,但不能通过http访问。我已经在网上做了一些研究,但似乎没有得到正确的配置

下面是我的web.config文件中的当前设置。

    <system.serviceModel>

    <bindings>
      <customBinding>
          <binding name="MyhttpsBinding">
          <binaryMessageEncoding/>
          <httpsTransport/> 
          </binding>
          <binding name="MyhttpBinding">
              <binaryMessageEncoding/>
              <httpTransport/>
          </binding>
      </customBinding>
    </bindings>

    <services>
      <service name="MyData" behaviorConfiguration="MyData">
        <endpoint address="" binding="customBinding" bindingConfiguration="MyData.customBinding.https" contract="MyData"/>
        <endpoint address="" binding="customBinding" bindingConfiguration="MyData.customBinding.http" contract="MyData"/>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="MyData" >
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
        </behavior>
        <behavior name="">
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
  </behaviors>

  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>

下面是我的servicerences.ClientConfig文件

<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="DataS" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
            <binding name="DataS1" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
        <customBinding>
            <binding name="CustomBinding_GetData">
                <binaryMessageEncoding />
                <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
            </binding>
        </customBinding>
    </bindings>

    <client>
        <endpoint address="//localhost/MyApp/Webservice/Data.asmx"
            binding="basicHttpBinding" bindingConfiguration="DataS1"
            contract="ServiceReference1.DataS" name="DataS" />

        <endpoint address="//localhost/MyApp/Webservice/GetData.svc"
            binding="customBinding" bindingConfiguration="CustomBinding_GetData"
            contract="GetData.GetData" name="CustomBinding_GetData" />
    </client>

</system.serviceModel>


我在上面错误地配置了什么,使得对http服务的调用失败

使用mexHttpBinding再添加一个端点,如下所示 endpoint address=“mexhttp”binding=“mexHttpBinding”contract=“imeadataexchange”/

而且

将服务行为添加到服务标记

<service name="MyData" behaviorConfiguration="MyData">


您已经直接针对服务端点(通过浏览器,而不是silverlight应用程序)进行了检查,但它不会加载到HTTP中?可以肯定的是,您没有用任何安全属性在代码中修饰您的服务类,对吗?通过浏览器直接检查服务端点对http和https都有效。我相信从https托管的Silverlight不会调用http服务。就像你在https上浏览一个网站,但有些网站内容来自http,浏览器会弹出警告消息。对于Silverlight,它看到了相同的漏洞,只是没有发出请求。您可以尝试在应用程序打开时通过监控网络流量来获取更多详细信息。运行Silverlight,打开浏览器调试器工具,查找预期的服务调用。问题解决了吗?如果没有,请显示最新的配置文件。我已使用当前(最新)的web.config和servicerences.ClientConfig设置更新了帖子。我仍然无法通过http访问该服务,但每个服务都可以通过https正常工作。我需要同时支持https和http。请将http端点的mex端点名称更改为MyhttpBinding,并将端点的bindingConfiguration名称更改为MyhttpBinding,契约应为接口(服务契约)使用mexhttp端点浏览具有基址的服务,如:http://localhost:234/Myservice/mexhttp(mexhttp端点的名称)如果可能,将您的解决方案共享给vinod。profileinfo@gmail.com,我会设法解决的