【发布时间】:2014-02-24 20:02:27
【问题描述】:
我有一个使用方法 GetCountries 的工作 WCF 服务。此函数返回custom object DTOCountry 的数组。然而,当我将我的方法转换为休息时,我似乎无法让它发挥作用。此外,它不断将我推向我的旧 BasicHttpBinding(在我的 WCF-Testclient 中)。
谁能指出我做错了什么?
我的配置
端点(注意链接的不同合同):
<service name="Partywhere.WCFService.Services.PublicServices" behaviorConfiguration="WCFService.PublicBehavior">
<endpoint address="" binding="basicHttpBinding" contract="Partywhere.WCFService.Services.IPW_UserService" behaviorConfiguration="WCFServiceEndpoint.PublicBehavior">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="GeoRest" binding="webHttpBinding" behaviorConfiguration="restfulBehavior" bindingConfiguration="MyWebHttp" contract="Partywhere.WCFService.Services.IPW_GeoService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" behaviorConfiguration="WCFServiceEndpoint.PublicBehavior"/>
</service>
行为:
<behaviors>
<endpointBehaviors>
<behavior name="WCFServiceEndpoint.PublicBehavior" />
<behavior name="restfulBehavior">
<webHttp></webHttp>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WCFService.PublicBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
我的绑定:
<bindings>
<basicHttpBinding>
<binding name="Partywhere.WCFService.Services.PublicServices" maxBufferSize="500000000" maxBufferPoolSize="524288" maxReceivedMessageSize="500000000">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</basicHttpBinding>
<mexHttpBinding>
<binding name="mex"/>
</mexHttpBinding>
<webHttpBinding>
<binding name="MyWebHttp" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" receiveTimeout="05:00:00" openTimeout="05:00:00" closeTimeout="05:00:00" sendTimeout="05:00:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
</bindings>
我的界面
[ServiceContract]
public interface IPW_GeoService
{
[OperationContract]
DTOCountry[] GetAllCountries();
}
我的 SVC
[WebGet(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetAllCountries")]
public DTOCountry[] GetAllCountries()
{
try
{
return _myCountryBl.GetAllCountries().ToArray();
}
catch (Exception ex)
{
throw;
}
}
问题:有人能发现配置错误吗?
我的方法如下Http://localhost/PW_GeoService.svc/GeoRest/GetAllCountries
注意::尝试使用 WebInvoke() 作为 WebGet()
注意2::尝试装饰界面以及我的服务的实现
更新:在处理客户端时出现错误:400 Bad-Request。
【问题讨论】:
-
什么版本的.net? 4.5?
-
是的,它是 4.5。我会把它添加到我的问题中
-
它给出了什么错误?是否抛出任何异常?
-
没有抛出异常/没有给出输出(Chrome)。在 Firefox/IE 中,我收到 400 异常“无效请求”
-
您可以在浏览器中浏览您的服务吗?