Wcf 调用REST服务时,如何排除404故障?
我创建了一个WCF服务并公开了两个端点;一个用于肥皂,一个用于休息。SOAP端点可以工作,可以从web客户端、控制台应用程序等访问。REST端点是今天早上创建的,无法工作。我确认SOAP服务仍然是可访问的,所以这个问题特定于今天上午所做的REST部分或配置更改 在浏览器中,我尝试导航到Wcf 调用REST服务时,如何排除404故障?,wcf,rest,Wcf,Rest,我创建了一个WCF服务并公开了两个端点;一个用于肥皂,一个用于休息。SOAP端点可以工作,可以从web客户端、控制台应用程序等访问。REST端点是今天早上创建的,无法工作。我确认SOAP服务仍然是可访问的,所以这个问题特定于今天上午所做的REST部分或配置更改 在浏览器中,我尝试导航到http://ABC:99/json/categories。我找不到404文件或目录 我向实现服务接口的类中的方法添加了以下属性: [WebInvoke(Method = "GET", ResponseFormat
http://ABC:99/json/categories
。我找不到404文件或目录
我向实现服务接口的类中的方法添加了以下属性:
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "categories")]
这是另一种方法:
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "reports/{categoryId}")]
配置文件的相关部分如下所示:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="NewBinding0" maxBufferSize="524288" maxReceivedMessageSize="524288" transferMode="StreamedResponse"
closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00" />
</basicHttpBinding>
</bindings>
<services>
<service name="XXX.ReportGenerator">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"
contract="XXX.YYY.IReportGenerator">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="ReportingSvc.JSON">
<endpoint address="json" binding="webHttpBinding"
contract="XXX.YYY.ReportingSvc.IReportGenerator" behaviorConfiguration="jsonEndpoint" />
<host>
<baseAddresses>
<add baseAddress="http://ABC:99/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="jsonEndpoint">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
非常感谢您的任何建议!谢谢 我无法在WCF中为您提供REST服务方面的具体帮助,因为我在那里没有经验,但WCF跟踪在过去的多个实例中一直是我的救命稻草。只需按照说明将以下内容添加到WCF服务的web.config:
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
,我相信它是默认安装的,用于查看跟踪并查看是否无法查明问题的根源
编辑
但是请注意,服务跟踪是超级资源密集型的,所以只有在需要它来调试问题时才打开它,然后在不再需要它时关闭它。我无法在WCF中为您提供REST服务方面的具体帮助,因为我在这方面没有经验,但WCF跟踪在过去的多个实例中一直是我的救命稻草。只需按照说明将以下内容添加到WCF服务的web.config:
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
,我相信它是默认安装的,用于查看跟踪并查看是否无法查明问题的根源
编辑
但是请注意,服务跟踪是超级资源密集型的,因此,只有当您需要它来调试问题时才打开它,然后在不再需要它时关闭它。如果您的方法只打算执行GET操作,那么最好使用WebGet属性,而不是使用WebInvoke并指定要获取的方法
此外,第一种方法的服务URL如下所示:
http://ABC:99/categories/json
第二种方法的URL为
http://ABC:99/reports/5/json
这是因为您将地址定义为“json”作为端点地址,并将其附加到基本URL+资源URL+端点地址。如果您的方法仅用于执行GET操作,则最好使用WebGet属性,而不是使用WebInvoke并指定要获取的方法
此外,第一种方法的服务URL如下所示:
http://ABC:99/categories/json
第二种方法的URL为
http://ABC:99/reports/5/json
这是因为您将地址定义为“json”作为您的端点地址,该地址将附加到基本URL+资源URL+端点地址。我是REST服务新手-您的REST端点和SOAP端点之间的合同不同有什么原因吗?@Zannjaminderson-我的错误。它们其实并没有什么不同。我更改了上面的代码。我是REST服务的新手-您的REST和SOAP端点之间的合同不同有什么原因吗?@Zannjaminderson-我的错误。它们其实并没有什么不同。我更改了上面的代码。