使用客户端凭据调用ASP.NET Web Service

时间:2011-04-21 17:56:09

标签: wcf web-services wcf-client

我正面临着需要调用第三方Web服务的情况。当我引用Web服务时,我在app.config中获得以下配置:

 <system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="GetCompanyInfoSoap" 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="Transport">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="">
                        <extendedProtectionPolicy policyEnforcement="Never" />
                    </transport>
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
            <binding name="GetCompanyInfoSoap1" 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="None"
                        realm="">
                        <extendedProtectionPolicy policyEnforcement="Never" />
                    </transport>
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
        <customBinding>
            <binding name="GetCompanyInfoSoap12">
                <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                    messageVersion="Soap12" writeEncoding="utf-8">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                </textMessageEncoding>
                <httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
                    maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                    realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                    useDefaultWebProxy="true" requireClientCertificate="false">
                    <extendedProtectionPolicy policyEnforcement="Never" />
                </httpsTransport>
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="https://api.capitaliq.com/ciqdotnet/api/2.0/GetCompanyInfo.asmx"
            binding="basicHttpBinding" bindingConfiguration="GetCompanyInfoSoap"
            contract="GetCompanyInfoSvc.GetCompanyInfoSoap" name="GetCompanyInfoSoap" />
        <endpoint address="https://api.capitaliq.com/ciqdotnet/api/2.0/GetCompanyInfo.asmx"
            binding="customBinding" bindingConfiguration="GetCompanyInfoSoap12"
            contract="GetCompanyInfoSvc.GetCompanyInfoSoap" name="GetCompanyInfoSoap12" />
    </client>
</system.serviceModel>

然后我用我的标准调用该服务。方法如图所示:

GetCompanyInfoSvc.GetCompanyInfoSoapClient p = new WindowsFormsApplication1.GetCompanyInfoSvc.GetCompanyInfoSoapClient("GetCompanyInfoSoap");
p.ClientCredentials.UserName.UserName = "cccccc";
p.ClientCredentials.UserName.Password = "ccccg";
GetCompanyInfoSvc.CompanySummary[] summ = p.GetCompanyInfo(new int[] { 18511 });

但是,调用始终失败并显示“需要身份验证”,似乎用户名/ pw未通过。我试过std。将其添加为ASMX Web引用并使用该调用的方法:

GetCompanyInfo c = new GetCompanyInfo();
c.Credentials = new System.Net.NetworkCredential("ccccc", "cccg");
CompanyDetail[] details = c.GetCompanyDetail(new int[] { 18511 });

这也不起作用。给我相同的“需要验证”错误。

我有什么遗失的吗?

0 个答案:

没有答案