tags:

views:

104

answers:

1
[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???

A: 

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>

Richard Szalay
Thanks a ton, how do i set the URI template if i want the parameters to be in the request body?? as sign in information are authentic data i do not want it to be exposed any suggestions??
Firstly, remove the UriTemplate completely. After that you would specify the data as {UserName:"username",Pasword:"password"} in the post body. It should be JSON because you have set `RequestFormat` to `WebMessageFormat.Json`.
Richard Szalay
Thanks for the right direction. I removed the URI and when i send {Username:"guru",Password:"1234"} as my request body it throws an error The server encountered an error processing the request. The exception message is 'The token '"' was expected but found 'U'.'. See server logs for more details. The exception stack trace is:</P><P class="intro"> at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3) at System.Xml.XmlExceptionHelper.ThrowTokenExpected(XmlDictionaryReader reader, String expected, Char found
Thanks all. I got it solved . the format was {"Username":"guru","Password":"1234"} :)