WCF REST服务的方法正在针对生产服务器与C#WCFClient一起使用。 他们还在localhost上的Dev-Environment中工作。 通过生产环境中的浏览器访问,该服务和wsdl也可以。
但是,当我从生产服务器上的服务访问任何方法时,将返回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.36 https://www.DS.XXX.com/qa/dLobby 400 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在prod上可用,因此它必须具有绑定和端点配置吗?
我正在使用来自第三方供应商的证书,该证书也可以正常工作。 我没看到任何帮助表示赞赏。如果您需要更多详细信息,请告诉我。
环境:Windows Server 2016,IIS
答案 0 :(得分: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。部署服务后,我们使用帮助文档查看如何访问它。
这是该服务的帮助文档。
有关WCF REST服务的更多信息,请参考以下链接:
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/wcf-web-http-programming-model