Как создать клиент для веб-службы, для которой требуется токен SAML

Итак, мне поручили по существу автоматизировать некоторые запросы веб-сервисов, которые исходят от моей компании. Поскольку я знаю местоположение wsdl, я создал простое пустое консольное приложение и добавил ссылку на службу, указывающую на этот wsdl. VS создал прокси-класс и файл app.config, который прекрасно сочетается с ним. Вот файл app.config, который он генерирует:

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
          <customBinding>
            <binding name="TestBinding">          
              <security authenticationMode="UserNameOverTransport" messageSecurityVersion="WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12">
              </security>
              <httpTransport/>
            </binding>
              <binding name="STSBinding">
                <security allowInsecureTransport="False"
                  authenticationMode="UserNameOverTransport"
                  requireSignatureConfirmation="false"
                  messageSecurityVersion="WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12">
                </security>          
                <textMessageEncoding messageVersion="Soap12WSAddressing10" />
                <httpsTransport/>
              </binding>           
          </customBinding> 
          <ws2007FederationHttpBinding>            
                <binding name="WS2007FederationHttpBinding_TestsService">
                    <security mode="TransportWithMessageCredential">
                        <message establishSecurityContext="false" issuedKeyType="BearerKey"
                            issuedTokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0">
                            <issuer address="https://sts.abc.com/idp/sts.wst" bindingConfiguration="STSBinding" binding="customBinding"/>
                            <issuerMetadata address="http://docs.oasis-open.org/ws-sx/ws-trust/200512/ws-trust-1.3.wsdl" />
                            <tokenRequestParameters>
                                <trust:SecondaryParameters xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
                                    <trust:TokenType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0</trust:TokenType>
                                    <trust:KeyType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer</trust:KeyType>
                                    <trust:Claims Dialect="http://schemas.xmlsoap.org/ws/2005/05/identity"
                                        xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
                                        <wsid:ClaimType Uri="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"
                                            Optional="true" xmlns:wsid="http://schemas.xmlsoap.org/ws/2005/05/identity" />
                                        <wsid:ClaimType Uri="http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
                                            Optional="true" xmlns:wsid="http://schemas.xmlsoap.org/ws/2005/05/identity" />
                                        <wsid:ClaimType Uri="http://schemas.xmlsoap.org/claims/AppId"
                                            xmlns:wsid="http://schemas.xmlsoap.org/ws/2005/05/identity" />
                                        <wsid:ClaimType Uri="http://schemas.xmlsoap.org/claims/Environment"
                                            xmlns:wsid="http://schemas.xmlsoap.org/ws/2005/05/identity" />
                                        <wsid:ClaimType Uri="http://schemas.xmlsoap.org/claims/SecondLvlAuthzId"
                                            xmlns:wsid="http://schemas.xmlsoap.org/ws/2005/05/identity" />
                                    </trust:Claims>
                                    <trust:CanonicalizationAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/10/xml-exc-c14n#</trust:CanonicalizationAlgorithm>
                                    <trust:EncryptionAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#aes256-cbc</trust:EncryptionAlgorithm>
                                </trust:SecondaryParameters>
                            </tokenRequestParameters>
                        </message>
                    </security>
                </binding>
            </ws2007FederationHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://Tests.abc.com/201308/TestsService.svc"
                binding="ws2007FederationHttpBinding" bindingConfiguration="WS2007FederationHttpBinding_TestsService"
                contract="ServiceReference1.TestsService" name="WS2007FederationHttpBinding_TestsService" />
        </client>
    </system.serviceModel>
</configuration>

Я сам добавил CustomBindings, очевидно, пытаясь поиграть с этим. До сих пор у меня было довольно много ошибок за ошибками, поскольку я пытаюсь использовать клиент следующим образом:

TestServiceClient vClient = new TestServiceClient();
ServiceProcessingDirectivesType vType = new ServiceProcessingDirectivesType();
UserContextType vUserContextType = new UserContextType();
ServiceCallContextType vServiceCallContextType = new ServiceCallContextType();
GetSummaryRequest vRequest = new GetSummaryRequest();

vClient.ClientCredentials.UserName.UserName = "Test";
vClient.ClientCredentials.UserName.UserName = "Pass";

vClient.GetSummary(vType, vUserContextType, ref vServiceCallContextType, vRequest);

У меня практически нет контроля над веб-сервисами, которые там есть. Я не уверен, что лучший способ продолжить отладку проблем. Я все еще пропускаю что-то из конфигурации? Если да, то откуда мне это знать?

Последняя ошибка, на которой я застрял прямо сейчас: "{"Невозможно определить партнерское соединение SP с помощью AppliesTo: https://dc-balances-acp.fmr.com/201308/BalancesService.svc"}"


person Tada    schedule 02.04.2014    source источник


Ответы (1)


Вы используете Федеративную безопасность.

Ошибка говорит о том, что она не может найти поставщика услуг для использования.

Адрес Клиента в Вашем конфиге и служба, которая вызывается по ошибке, не совпадают.

Похоже, что ваша программа не использует конфигурацию, которую вы разместили.

person Shiraz Bhaiji    schedule 02.04.2014
comment
Спасибо за ответ. Я подтвердил, что приложение правильно использует настройки файла app.config. Возможно, что-то не так с моей конфигурацией? - person Tada; 02.04.2014