3

我试图通过 .Net 代码(控制台应用程序)使用工作日 Web 服务进行呼叫。

我已经添加了服务参考。所有命名空间的细节都很好,我能够获取命名空间中所有类的成员和方法。

当我尝试执行一个方法时,它会抛出一个错误(Client.AuthenticationErro(无效的用户名/密码)。我已经在代码中提供了客户端凭据并使用基本绑定。请在下面找到我的代码和 App.Config文件。但是当我使用 SOAP UI 进行 Web 服务调用时,一切正常。

class Demo
{

        static void GetPhoto(string EmployeeID)
        {
            HR.Employee_Image_GetType EmpImageGetType = new HR.Employee_Image_GetType();
            EmpImageGetType.version = "v17";
            HR.IDType EmpIDType = new HR.IDType();
            EmpIDType.Value = EmployeeID;
            HR.External_Integration_ID_Reference_DataType IDRef = new HR.External_Integration_ID_Reference_DataType();
            IDRef.ID = EmpIDType;

            HR.Employee_ReferenceType[] EmpRefArray = new HR.Employee_ReferenceType[1];
            HR.Employee_ReferenceType Empref = new HR.Employee_ReferenceType();
            Empref.Integration_ID_Reference = IDRef;
            EmpRefArray[0] = Empref;
            EmpImageGetType.Employee_Reference = EmpRefArray;
            var binding=new BasicHttpBinding(BasicHttpSecurityMode.Transport);
            binding.Security.Transport.ClientCredentialType=HttpClientCredentialType.Basic;
            Human_ResourcesPortClient proxy = new Human_ResourcesPortClient((System.ServiceModel.Channels.Binding)binding, new EndpointAddress("https://impl-cc.workday.com/ccx/service/amat1/Human_Resources/v17?wsdl"));
            proxy.ClientCredentials.HttpDigest.ClientCredential.UserName = "XXXXXX@XXXYY";
            proxy.ClientCredentials.HttpDigest.ClientCredential.Password = "xxxx";
            proxy.ChannelFactory.Credentials.HttpDigest.ClientCredential.UserName = "XXXXXX@XXXYY";
            proxy.ChannelFactory.Credentials.HttpDigest.ClientCredential.Password = "xxxx";
            proxy.ClientCredentials.UserName.UserName = "XXXXXX@XXXYY";
            proxy.ClientCredentials.UserName.Password = "xxxxx";
            try
            {
               HR.Employee_ImageType EmpImageType = proxy.Get_Employee_Image(EmpImageGetType);

                Console.WriteLine("Success");

            }
            catch (Exception exp)
            {
                Console.WriteLine("Exception:" +exp.Message +exp.StackTrace);

            }
            Console.ReadLine();
        }


      public static void BypassCertificateError()
        { ServicePointManager.ServerCertificateValidationCallback =
            delegate(Object sender1, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
            { return true; };
        }

    }



 - App.Config
<?xml version="1.0"?>
<configuration>
    <configSections>
    </configSections>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="Human_ResourcesBinding" 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="TransportWithMessageCredential">
                        <transport clientCredentialType="Basic" proxyCredentialType="Basic"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
                <binding name="Human_ResourcesBinding1" 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="TransportWithMessageCredential">
                        <transport clientCredentialType="Basic" proxyCredentialType="Basic"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://impl-cc.workday.com/ccx/service/amat1/Human_Resources/v17"
                binding="basicHttpBinding" bindingConfiguration="Human_ResourcesBinding"
                contract="HR.Human_ResourcesPort" name="Human_Resources" />
        </client>
    </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>

**

谁能帮帮我?

4

0 回答 0