gpt4 book ai didi

c# - 带有 webHttpBinding 的 WCF 服务; 404错误

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:00 25 4
gpt4 key购买 nike

当参数不匹配时,如下方框中配置的服务会抛出 404 吗?在这种情况下,参数是复杂类型,每次调用 SearchJson 方法都会返回 404...(它甚至允许使用 WebInvoke 选项并且没有 UriTemplate 吗?)

服务已启动并正在运行(我可以使用“生成您的客户端..?wsdl”-stuff 调用测试页)

服务方法配置为:

    [OperationContract]
[FaultContract(typeof(Exception))]
[WebInvoke(ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json)]
SearchResponse SearchJson(SearchRequest req);

有什么解决办法吗?

顺便说一句。这是我用于测试的...无论我更改什么参数,都会返回 404...当我将 WebInvoke 更改为 WebGet 并使用简单类型作为参数(如字符串)时,我只能触发不同的行为... 然后我得到一个 405

WebRequest req = HttpWebRequest.Create("http://localhost:8800/SearchService/SearchJson");
req.Method = "POST";
req.ContentType = "application/json";
req.ContentLength = 354;
WebResponse resp = req.GetResponse();

这是配置:

  <service name="SearchEngine.SearchService" behaviorConfiguration="HTTPGetBehavior">
<endpoint address="SearchEngine.SearchService"
behaviorConfiguration="ajaxBehavior"
binding="webHttpBinding"
contract="SearchEngine.ISearchInterface" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8800/SearchService" />
</baseAddresses>
</host>
</service>

最佳答案

好的,我明白了......

我不知道为什么,但是如果我使用“WebServiceHost”而不是“ServiceHost”来使用 WCF 服务,我至少可以通过 .. 我的 SearchRequest 对象是空的,但我希望能弄清楚为什么..

关于c# - 带有 webHttpBinding 的 WCF 服务; 404错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1109317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com