HTTPS上的RESTful GET返回错误请求400错误

时间:2013-11-13 00:49:47

标签: wcf rest https

我最近需要更改我的REST WCF服务以使用SSL。 它托管在IIS 6中,并且在SSL要求之前工作正常。

我无法弄清楚为什么我收到400错误请求错误。 我有诊断记录,它说

<Message>The body of the message cannot be read because it is empty.</Message>

web.config看起来像:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <webServices>
            <protocols>
            <add name="HttpGet"/>
        </protocols>
        </webServices>
        <identity impersonate="true"/>
        <customErrors mode="Off"/>
    </system.web>

    <startup>
        <supportedRuntime version="v4.0.30319"/>
    </startup>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IMessageService">
                    <security mode="Transport">
                        <transport clientCredentialType="None"/>
                    </security>
                </binding>
             </wsHttpBinding>
             <webHttpBinding>
                 <binding name ="webBinding">
                 </binding>
             </webHttpBinding>
             <basicHttpBinding>
                 <binding name="httpBinding">
                     <security mode="Transport">
                         <transport clientCredentialType = "None"/>
                     </security>
                 </binding>
             </basicHttpBinding>
        </bindings>
        <services>
            <service behaviorConfiguration="metadataBehavior"
                     name="XXXDataService.XXXDataService">
                <endpoint address="" 
                          binding="wsHttpBinding"
                          bindingNamespace="http://blah.blah.blah.com/XXXDataService/"
                          bindingConfiguration="WSHttpBinding_IMessageService"
                          contract="ZZZDataService.IZZZDataServices">
                </endpoint>
                <endpoint address="mex" 
                          binding="mexHttpsBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <standardEndpoints>
            <webHttpEndpoint>
                <standardEndpoint name="" 
                                  helpEnabled="true" 
                                  automaticFormatSelectionEnabled="true" />
            </webHttpEndpoint>
        </standardEndpoints>
        <behaviors>
            <serviceBehaviors>
                <behavior name="metadataBehavior">
                    <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false"/>
                    <serviceDebug includeExceptionDetailInFaults="True" 
                                  httpHelpPageEnabled="True"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

我只删除了诊断部分,需要通过替换XXX和ZZZ来保护名称。

非常感谢任何帮助或建议。

服务实施:

[ServiceBehavior(Namespace="blah.blah.blah.com", Name="XXXDataService")] 
public class YYYDataService : IYYYDataService 
{ 
    public string GetUser(string id) 
    { 
        string result = string.Empty; 
        using (YYYAdmintTree tree = new YYYAdmintTree()) // used for accessing DB 
        { 
            result = tree.GetUserById(id, 1); 
        } 
        return result; 
    }
} 

合同:

[ServiceContract(Namespace="https://blah.blah.blah.com", Name="XXXDataService")]
public interface IYYYDataService
{
    [OperationContract]
    [WebGet(UriTemplate="/GetUser/{id}", ResponseFormat=WebMessageFormat.Json)]
    string GetUserById(string id);
}

1 个答案:

答案 0 :(得分:0)

将错误参数作为输入传递时出现错误400。如果您再次将XML或JSON作为输入检查传递。如果服务器无法找到它,它会给你错误404.但400表示输入提供肯定有问题。