none
How can send the credentials to call the service? RRS feed

  • Question

  • Hi ,

    Ho to make basic authentication or send the credential information to service?

    I have added a service reference (JAVA service reference) to the solution. When i tried to make a call to service, it hits an error saying unauthorised service request. How can I send the credentials when I call a service? I want to do a basic authentication.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using System.Net;
    using System.Net.Security;
    
    
    namespace consumerApp
    {
        public partial class Program
        {
            static void Main(string[] args)
            {
    
                ServiceReference2.ServicePortTypeClient client = new ServiceReference2.ServicePortTypeClient();
                
                ServiceReference2.PartType part = new ServiceReference2.PartType();
                part.price = "49";
                ServiceReference2.ResponseType response = client.getPart(part);
                Console.WriteLine("Name: " + response.major + " Price: " + response.minor);
            }
           
        }
    
    }
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="<JAVA service url> value="SVCUrl" />
        <add key="<http,mylogout url>value="LogoutUrl"/>
      </appSettings>
      <system.net>
        <defaultProxy>
          <proxy autoDetect="True"/>
        </defaultProxy>
      </system.net>
      
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="SoapBinding" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                        useDefaultWebProxy="true">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        <!--<security mode="None">
                            <transport clientCredentialType="None" proxyCredentialType="Windows"
                                realm="" />
                            <message clientCredentialType="UserName" algorithmSuite="Default" />
                        </security>-->
                      <security mode="TransportCredentialOnly">
                        <transport clientCredentialType="Basic" realm=""/>
                      </security>
                    </binding>
                    <binding name="VisualizationSoapBinding1" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                        useDefaultWebProxy="true">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        <!--<security mode="None">
                            <transport clientCredentialType="None" proxyCredentialType="Windows"
                                realm="" />
                            <message clientCredentialType="UserName" algorithmSuite="Default" />
                        </security>-->
                      <security mode="None">
                        <transport  proxyCredentialType="Windows" realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                      </security>
                    </binding>
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="<JAVA service endpoiunt>" bindingConfiguration="SoapBinding1"
                    contract="ServiceReference2.ServicePortType" name="ServicePort1" />
            </client>
        </system.serviceModel>
    </configuration>

    I am new to WCF I have earlier used asmx procedure. Ho can i do this?

    Thanks


    Roopini



    • Edited by Roopini Saturday, January 18, 2014 1:55 PM
    Saturday, January 18, 2014 1:52 PM

All replies

  • Hi,

    If you want to do a basic authentication, then please try to modify your endpoint configure with the correct binding config:

    <endpoint address="<JAVA service endpoiunt>" 
              bindingConfiguration="SoapBinding" 
              binding="basicHttpBinding"
              contract="ServiceReference2.ServicePortType" name="ServicePort1" />


    Then in the client please set the following:

    client.ClientCredentials.UserName.UserName = Username;
    client.ClientCredentials.UserName.Password = Password;

    For more information, please try to refer to:
    #Transport Security with Basic Authentication:
    http://msdn.microsoft.com/en-us/library/ms733775(v=vs.110).aspx .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, January 20, 2014 9:32 AM
    Moderator
  • Hi Amy,

    I tried to use this, but it said that it is "object is read-only"

    The HTTP request is unauthorized with client authentication scheme 'Negotiate' basic realm = "SVCin"/"SVC native".

    I again added the svc reference after deleting the previous, and security mode it generated was "Transport" 

     <security mode="Transport">//this was generated when reference was added
                          <transport clientCredentialType="Windows"> //i added this clientcredentialtype 
                          </transport>
                      </security>

    <security mode="Transport"><transport clientcredentialtype="Windows"></transport> </security>


    • Edited by Roopini Monday, January 20, 2014 9:39 AM
    Monday, January 20, 2014 9:36 AM