0

I tried to make REST / SOAP endpoints for a WCF service, I test it using POSTMAN , it returns 401 unauthorized error. Anyone please help to fix this, been few hours trying to figure out this issue.

this is my postman enter image description here

web config:

<system.web>
        <compilation debug="true" targetFramework="4.7.2" />
        <httpRuntime targetFramework="4.5" />
        <customErrors mode="Off" />
        <sessionState mode="InProc" cookieless="true" timeout="1440" />
    <authentication mode="None" />
    </system.web>
<system.serviceModel>
        <client>
            <endpoint address="http://localhost:59900/LoginSVC.svc"
             binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILoginSVC"
             contract="ServiceReference1.ILoginSVC" name="BasicHttpBinding_ILoginSVC" />
        </client>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_ILoginSVC" />
            </basicHttpBinding>
            <webHttpBinding>
                <binding name="webHttpBindingILoginSVC" />
            </webHttpBinding>
            
        </bindings>

        <services>
            <service name="LoginSVC.LoginSVC">
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:59900/LoginSVC" />
                    </baseAddresses>
                </host>
                <endpoint address="soap" binding="basicHttpBinding" contract="LoginSVC.ILoginSVC">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="REST" binding="webHttpBinding" contract="LoginSVC.ILoginSVC" behaviorConfiguration="RESTEndPointBehaviour">
                </endpoint>
            </service>
        </services>

        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!--To avoid disclosing metadata information, set the values below to false before deployment-->
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <!--To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information-->
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="RESTEndPointBehaviour">
                    <webHttp />
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="1" />
    </system.serviceModel>

my interface file :

[OperationContract]
    [WebInvoke(Method = "POST",
        //UriTemplate = "/Login_checkUser",
        BodyStyle = WebMessageBodyStyle.Wrapped,
        ResponseFormat = WebMessageFormat.Json)]
    string Login_checkUser(string username, string password);
woo25
  • 5
  • 6
  • Maybe you can provide more details like config file, you can try putting `` into web.config in ``. – Lan Huang Mar 02 '22 at 09:57
  • @LanHuang I added my web config and service interface – woo25 Mar 02 '22 at 13:34
  • Please try adding the security tag to your bindings and make sure the client side and server side are consistent ` `https://stackoverflow.com/questions/2205038/401-unauthorized-error-wcf-security-binding – Lan Huang Mar 03 '22 at 09:50
  • @LanHuang, I tried to add the security tag , but still returns bad request. – woo25 Mar 03 '22 at 11:43
  • You can check out [this thread](https://stackoverflow.com/questions/186631/rest-soap-endpoints-for-a-wcf-service) which provides a way to expose a service in two different endpoints. – Lan Huang Mar 04 '22 at 06:06

0 Answers0