如何配置WCF服务以使用HTTP和HTTPS - 多个绑定不起作用

时间:2014-08-06 14:32:12

标签: web-services wcf silverlight-4.0 svc service-model

对Silver-light和WCF来说还是比较新的,所以请耐心等待。

我有银光应用,可以调用.svc服务。该服务是通过https成功调用的,但我也想通过普通的http来调用它。

我需要对下面的web.config和ServiceReferences.ClientConfig文件进行哪些修改。

我的Web.config文件中的完整system.serviceModel部分就是这个。

 <system.serviceModel>     
    <bindings>
        <customBinding>
            <binding name="MyApp.Web.GetData.customBinding" receiveTimeout="00:30:00" sendTimeout="00:30:00" >
                <binaryMessageEncoding/>
                <httpsTransport/>
            </binding>
        </customBinding>
    </bindings>
    <services>
        <service name="MyApp.Web.GetData">
            <endpoint address="" binding="customBinding" bindingConfiguration="MyApp.Web.GetData.customBinding" contract="MyApp.Web.GetData" />
            <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
        </service>
    </services>      
    <behaviors>
        <serviceBehaviors>
            <behavior name="MyApp.Web.GetData">
                <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
                <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
            </behavior>
            <behavior name="">
                <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>       
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>

我的完整ServiceReferences.ClientConfig文件位于

之下
<configuration>
<system.serviceModel>
    <bindings>
        <customBinding>
            <binding name="CustomBinding_GetData">
                <binaryMessageEncoding />
                <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
           </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="//localhost/MyApp.Web/Webservice/GetData.svc"
            binding="customBinding" bindingConfiguration="CustomBinding_GetData"
            contract="GetData.GetData" name="CustomBinding_GetData" />
    </client>
</system.serviceModel>

1 个答案:

答案 0 :(得分:0)

尝试添加另一个端点和另一个没有ssl的绑定:                                                                                                                                                                                 

        </customBinding>
    </bindings>
    <client>
        <endpoint address="//localhost/MyApp.Web/Webservice/GetData.svc"
            binding="customBinding" bindingConfiguration="CustomBinding_GetData-ssl"
            contract="GetData.GetData" name="CustomBinding_GetData-ssl" />
        <endpoint address="//localhost/MyApp.Web/Webservice/GetData.svc"
            binding="customBinding" bindingConfiguration="CustomBinding_GetData"
            contract="GetData.GetData" name="CustomBinding_GetData" />
    </client>
</system.serviceModel>