【问题标题】:REST Post request gives end point not found errorREST Post 请求给出未找到端点错误
【发布时间】:2010-01-16 07:27:28
【问题描述】:
[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>

我正在使用提琴手来创建我的帖子请求。当我提供完整的 URI 时,它可以工作,如下所示 https://test.pxchange.com/PatientExchangeWCFPostService/Service.svc/SignIn/Username/guru/Password/122

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

点赞网址:https://test.pxchange.com/PatientExchangeWCFPostService/Service.svc

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

有什么建议吗???

【问题讨论】:

    标签: c# wcf rest


    【解决方案1】:

    由于您的WebInvoke 属性指定了UriTemplate,因此以帖子形式发送的数据不再与模板匹配,从而导致“找不到端点”错误。

    另外,您的请求是 https,但您只有一个 http 地址前缀。将 https 地址添加到&lt;serviceHostingEnvironment&gt; -&gt; &lt;baseAddressPrefixFilters&gt;

    【讨论】:

    • 非常感谢,如果我希望参数位于请求正文中,如何设置 URI 模板?由于登录信息是真实数据,我不希望它暴露任何建议??
    • 首先,彻底删除 UriTemplate。之后,您将在帖子正文中将数据指定为 {UserName:"username",Pasword:"password"}。它应该是 JSON,因为您已将 RequestFormat 设置为 WebMessageFormat.Json
    • 感谢正确的方向。我删除了 URI,当我发送 {Username:"guru",Password:"1234"} 作为我的请求正文时,它会引发错误服务器在处理请求时遇到错误。异常消息是 'The token '"' was expected but found 'U'.'。有关更多详细信息,请参阅服务器日志。异常堆栈跟踪是:

      at System.Xml。 XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader,String res,String arg1,String arg2,String arg3)在System.Xml.XmlExceptionHelper.ThrowTokenExpected(XmlDictionaryReader reader,String预期,Char找到

    • 谢谢大家。我解决了。格式为 {"Username":"guru","Password":"1234"} :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    相关资源
    最近更新 更多