REST Post请求给出端点未找到错误

时间:2010-01-15 23:19:15

标签: c# wcf rest

[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

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

与网址类似:https://test.pxchange.com/PatientExchangeWCFPostService/Service.svc

身体:登入/用户名/大师/口令/ 122

任何建议???

1 个答案:

答案 0 :(得分:0)

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

此外,您的请求是 https ,但您只有 http 地址前缀。将 https 地址添加到<serviceHostingEnvironment> -> <baseAddressPrefixFilters>