REST Post 请求给出了未找到端点的错误 [英] REST Post request gives end point not found error

查看:68
本文介绍了REST Post 请求给出了未找到端点的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[OperationContract]
[WebInvoke(Method="POST", 
           BodyStyle = WebMessageBodyStyle.Wrapped,
           ResponseFormat = WebMessageFormat.Json,
           UriTemplate= "SignIn/Username/{Username}/Password/{Password}",
           RequestFormat= WebMessageFormat.Json)]

 string SignIn(string Username,string Password);

我的配置文件看起来像

                <security mode="Transport">
                    <transport clientCredentialType ="None"/>
                </security>
            </binding>
        </webHttpBinding>
    </bindings>
    <serviceHostingEnvironment>
        <baseAddressPrefixFilters>
            <add prefix="http://test.pxchange.com/patientExchangeWCFPostService/Service.svc" />
        </baseAddressPrefixFilters>
    </serviceHostingEnvironment>

    <services>
        <service name="MyService" behaviorConfiguration="returnFaults">
            <endpoint address=""   contract="IMyService" binding="webHttpBinding" bindingConfiguration ="wsHttpEndpointBinding" behaviorConfiguration="AjaxBehavior"/>

        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="returnFaults">
                <serviceDebug includeExceptionDetailInFaults="true"/>
                <serviceMetadata httpGetEnabled="true"/>
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="AjaxBehavior">
                <webHttp/>
            </behavior>
        </endpointBehaviors>
    </behaviors>
</system.serviceModel>
<system.web>
    <compilation debug="true">
        <assemblies>
            <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

            <add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="Microsoft.SqlServer.TxScript, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
        </assemblies>
    </compilation>
</system.web>

我正在使用 fiddler 创建我的帖子请求.当我提供如下所示的完整 URI 时它会起作用https://test.pxchange.com/PatientExchangeWCFPostService/Service.svc/SignIn/Username/guru/Password/122

I am using fiddler to create my post request.It works when I give complete URI like below https://test.pxchange.com/PatientExchangeWCFPostService/Service.svc/SignIn/Username/guru/Password/122

但是当我将 URL 和请求正文分开时,它给我找不到终点.

But when i separate the URL and request body it gives me end point not found.

喜欢网址:https://test.pxchange.com/PatientExchangeWCFPostService/Service.svc

正文:登录/用户名/guru/密码/122

Body:SignIn/Username/guru/Password/122

有什么建议???

推荐答案

因为你的 WebInvoke 属性指定了一个 UriTemplate,发送数据作为 post 不再匹配模板,这会导致找不到端点"错误.

Because your WebInvoke attribute specifies a UriTemplate, sending the data as post no longer matches the template, which results in an "endpoint not found" error.

此外,您的请求是 https,但您只有一个 http 地址前缀.将 https 地址添加到 ;->

Also, your request is https but you only have an http address prefix. Add an https address to <serviceHostingEnvironment> -> <baseAddressPrefixFilters>

这篇关于REST Post 请求给出了未找到端点的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆