REST Post request gives end point not found error

2019-09-03 11:45发布

问题:

[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);

My config file looks like

                <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>

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

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

Like URL:https://test.pxchange.com/PatientExchangeWCFPostService/Service.svc

Body:SignIn/Username/guru/Password/122

Any suggestions???

回答1:

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.

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



标签: c# wcf rest