2

我有一个运行良好的 WCF REST-ful JSON 服务。当我尝试将其用于 HTTPS 时,就会出现问题。Web.config 如下:

 <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="StreamedRequestWebBinding" bypassProxyOnLocal="true" useDefaultWebProxy="false" hostNameComparisonMode="WeakWildcard" sendTimeout="10:15:00" openTimeout="10:15:00" receiveTimeout="10:15:00" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="StreamedRequest">
          <security mode="Transport">
            <transport clientCredentialType = "None"  />
          </security>
          <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service name="WcfRESTFullJSON.Service1" behaviorConfiguration="ServiceBehaviour">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="StreamedRequestWebBinding" contract="WcfRESTFullJSON.IService1" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <!--Him-->
          <webHttp automaticFormatSelectionEnabled="true" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
  </system.serviceModel>

我在 IIS 上配置了一个自制的证书。在客户端我有:

WebClient WC;
...
WC.UploadData(URL, "POST", asciiBytes);

我们得到什么:

The remote server returned an error: (500) Internal Server Error.

可能是什么问题?

4

3 回答 3

1

问题已解决。这是对以下行中端点行为的缺失引用 ...endpoint behaviorConfiguration="web" address="" binding="webHttpBinding" bindingConfiguration="StreamedRequestWebBinding" contract="WcfRESTFullJSON.IService1"... 在 Web 中。配置如下。感谢各位朋友的帮助!最终在使用 WCF 服务实现 REST 的 5 个重要原则一文中找到了解决方案

    <services>
  <service name="WcfRESTFullJSON.Service1" behaviorConfiguration="ServiceBehaviour">
    <endpoint  behaviorConfiguration="web" address="" binding="webHttpBinding" bindingConfiguration="StreamedRequestWebBinding" contract="WcfRESTFullJSON.IService1" />
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <!--Him-->
      <webHttp automaticFormatSelectionEnabled="true" />
    </behavior>
  </endpointBehaviors>
于 2012-12-13T18:48:17.547 回答
0
 See Complete config file
<configuration>   <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <webServices>
          <protocols>
            <add name="HttpsGet"/>
            <add name="HttpsPost"/>
          </protocols>
        </webServices>   </system.web>   <system.serviceModel>
        <services>
          <service  name="RESTTEST.RestTestService" behaviorConfiguration="ServiceBehavior">

            <endpoint address="" binding="webHttpBinding" 
                      contract="RESTTEST.IRestTestService" 
                      bindingConfiguration="sslBinding"
                      behaviorConfiguration="web"
                      ></endpoint>
            <endpoint address="mex"
                  binding="mexHttpsBinding"
                  contract="IMetadataExchange" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before
    deployment -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before
    deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="web">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <bindings>
          <webHttpBinding>
            <binding name="sslBinding" crossDomainScriptAccessEnabled="true">
              <security mode="Transport">
              </security>
            </binding>
          </webHttpBinding>    
          </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false">
        </serviceHostingEnvironment>
        <standardEndpoints>
          <webHttpEndpoint>
            <standardEndpoint crossDomainScriptAccessEnabled="true"></standardEndpoint>
          </webHttpEndpoint>
          <webScriptEndpoint>
            <standardEndpoint name="" crossDomainScriptAccessEnabled="true" />
          </webScriptEndpoint>
        </standardEndpoints>   </system.serviceModel>   <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
        <httpProtocol>
          <customHeaders>
            <add name="Access-Control-Allow-Origin" value="*" />
            <add name="Access-Control-Allow-Headers" value="Content-Type" />
          </customHeaders>
        </httpProtocol>   </system.webServer> </configuration>
于 2014-07-10T15:27:49.873 回答
0

由于 SSL 是 HTTP 下的协议,因此通常无需在 web.config 中配置任何额外内容(只有一个新绑定)。如果您使用 SSL,另一件会发生变化的事情是端口……您可能需要更新防火墙或检查您的请求是否发送到正确的端口。

于 2012-12-12T21:01:02.407 回答