WCF方法在生产中返回400错误的请求

问题描述 投票:0回答:1

WCF REST服务的方法正在针对Production-Server与C#WCFClient一起使用。他们还在localhost上的Dev-Environment中工作。通过生产中的浏览器访问,服务和wsdl也可以。

Access to svc

Access to wsdl

但是当我从Production-Server上的服务访问任何方法时,将返回400 Bad Request。IIS日志还显示了400:GET /WCD/WCF.svc/GetNextGuestNumber-443-Mozilla / 5.0 +(Windows + NT + 10.0; + Win64; + x64)+ AppleWebKit / 537.36 +(KHTML,+ like + Gecko)+ Chrome / 83.0.4103.61 + Safari / 537.36https://www.DS.XXX.com/qa/dLobby400 0 0 46

这是我在Production中的web.config:

<?xml version="1.0"?>
  <configuration>  
    <appSettings>
      <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      <add key="WBCCNN" value="PQkSAXkRXNsanbA5xK1KBZZqu+oxrJbssQlEiM1Fi+N2Vnz0F5QfAetqILb0QeLwlF7jMZ57k9J8sIlAJ1TRjtfgwh0V88Q2Kl/20Cny2WCTawWyDSECKg=="/>
    </appSettings>
    <system.web>  
      <compilation debug="false" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5"/>
    </system.web>  
    <system.serviceModel>  
      <services>  
        <service name="DS.XXX.Services.WCF" behaviorConfiguration="DSServiceBehavior">  
          <endpoint address=""  
              binding="basicHttpBinding"  
              bindingConfiguration="secureHttpBinding"  
              contract="DS.XXX.Services.IWCF"/>  
          <endpoint address="mex"  
              binding="mexHttpsBinding"  
              contract="IMetadataExchange" />  
        </service>  
      </services>  
      <bindings>  
        <basicHttpBinding>  
          <binding name="secureHttpBinding">  
            <security mode="Transport"> 
            </security>  
          </binding>  
        </basicHttpBinding>  
      </bindings>  
      <behaviors>  
        <serviceBehaviors>
          <behavior name="DSServiceBehavior">
            <serviceMetadata httpsGetEnabled="true" httpsGetUrl="" />
            <serviceDebug includeExceptionDetailInFaults="false"/>
          </behavior> 
        </serviceBehaviors>  
      </behaviors>  
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />  
    </system.serviceModel>  
    <system.webServer>  
      <modules runAllManagedModulesForAllRequests="true"/>  
    </system.webServer>  
  </configuration>

[使用Axios从REACT JS应用程序中调用方法

const res = await API.get("/GetNextGuestNumber");

来自Axios的API的配置如下:

import axios from "axios";
import global from "../config";

export default axios.create({
  baseURL: global.webServicesUrl,
  headers: { "Content-Type": "application/json" }
});

由于该服务正在开发dev上,并且svc和wsdl在产品上可以访问,因此它必须具有绑定和端点配置吗?

我正在使用第三方供应商的证书,该证书也可以正常工作。我没看到任何帮助表示赞赏。如果您需要更多详细信息,请告诉我。

Env.:Windows Server 2016,IIS

wcf axios wcf-binding
1个回答
0
投票

绑定中有错误。您应该使用webhttpbinding来构建WCF REST服务,但是我在配置文件中看到您使用basichttpbinding。在这种情况下,当您使用JS访问服务时,将收到400错误。

        <services>
        <service name="Demo_rest_IIS.Service1"
                 behaviorConfiguration="UserServiceBehavior">
            <endpoint address=""
                      binding="webHttpBinding"
                      contract="Demo_rest_IIS.IService1"
                      behaviorConfiguration="ESEndPointBehavior" bindingConfiguration="bind"/>
        </service>
    </services>
    <behaviors>
        <endpointBehaviors>
            <behavior name="ESEndPointBehavior">
                <webHttp helpEnabled="true"/>
            </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="UserServiceBehavior">
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>

这是我在IIS中部署的WCF Rest服务的配置文件。

    [OperationContract]
    [WebGet(UriTemplate = "user/?name={name}",RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    Result GetUserData(string name);
    [OperationContract]
    [WebInvoke(UriTemplate = "user", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    Result PostUserData(UserData user);
    [OperationContract]
    [WebInvoke(Method = "PUT", UriTemplate = "user", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    Result PutUserData(UserData user);
    [OperationContract]
    [WebInvoke(Method = "DELETE", UriTemplate = "user", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    Result DeleteUserData(UserData user);

这是服务的接口。在配置文件中,我将helpenabled的值设置为true。部署服务后,我们使用帮助文档查看如何访问它。

enter image description here

这是该服务的帮助文档。

有关WCF REST服务的更多信息,请参考以下链接:

https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/wcf-web-http-programming-model

© www.soinside.com 2019 - 2024. All rights reserved.