【发布时间】:2020-01-11 09:29:25
【问题描述】:
我尝试在现有 WCF 应用程序中添加第二个端点,但我的 REST 方法不起作用。 我创建了新界面
[ServiceContract]
public interface IRestService
{
[OperationContract]
[WebGet(UriTemplate = "RestURI", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string SomeMethod();
}
并在现有服务中实现
public string SomeMethodImplementation()
{
//some logic
}
我正在尝试使用 basicaddress/service/RestURI 访问此方法,但收到 400 Bad Request 响应。
之后,我在配置文件中添加了协议映射、第二个端点和端点行为,但它没有帮助。
现在我的配置文件如下所示:
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="webHttpBinding"/>
</protocolMapping>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false 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="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="servicename">
<endpoint address="" binding="webHttpBinding" contract="IRestService" behaviorConfiguration="web"/>
<endpoint address="" binding="basicHttpBinding" contract="ISoapService"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" receiveTimeout="00:10:00" sendTimeout="00:10:00">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16348" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
</binding>
</basicHttpBinding>
</bindings>
我不再收到任何 400,而是“由于 EndpointDispatcher 的 AddressFilter 不匹配,无法在接收器处处理”。出现错误。同样在添加protocolMapping 之后,当我在浏览器中打开wsdl 时,我的soap 方法也消失了。没有它,我的 rest 方法可以在列表中看到,如下所示:
<wsdl:port name="BasicHttpBinding_IRestService" binding="i0:BasicHttpBinding_IRestService">
之后,我在我的服务属性中添加了 AddressFilterMode = AddressFilterMode.Any) 但它没有帮助。
我在这里找到了很多答案,但不知何故没有一个可以帮助我解决这个问题。 我错过了什么?
【问题讨论】:
-
下面的帖子有三个链接。如果您有任何问题,请告诉我。 social.msdn.microsoft.com/Forums/windows/en-US/…