C # веб-сервис потребляет с заголовком оазиса безопасности wss - PullRequest
0 голосов
/ 25 августа 2018

Я новичок в веб-сервисах, мне пришлось отправить файл с помощью веб-сервиса и поймать ответ, моя проблема в том, что я не могу сгенерировать действительный заголовок SOAP. я использую c # WCF visual studio 2017

Потребляемый веб-сервис: https://facturaelectronica.dian.gov.co/habilitacion/B2BIntegrationEngine/FacturaElectronica/facturaElectronica.wsdl

Спецификации для заголовка согласно документации от провайдера:

Пример запроса с использованием Base64

POST /B2BIntegrationEngine/FacturaElectronica HTTP/1.1 Accept-Encoding: gzip,deflate Content-Type: text/xml;charset=UTF-8 SOAPAction: "" Content-Length: 3342 Host: 192.168.250.65:9080 Connection: Keep-Alive User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rep="http://www.dian.gov.co/servicios/facturaelectronica/ReportarFactura">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username><!--Removed--></wsse:Username>
<wsse:Password><!--Removed--></wsse:Password>
<wsse:NonceEncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">FmbZRkx1jh2A+imgjD2fLQ==</wsse:Nonce>
<wsu:Created>2015-10-06T12:00:33.762Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>

Но когда я пытаюсь сгенерировать его, я получаю только это:

<s:Envelope xmln s:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username><!--Removed--></wsse:Username>
<wsse:Password><!--Removed--></wsse:Password>
<wsse: Nonce>t21C05VjRqomc+OehZoSzwqhmaM=</wsse:Nonce>
<wsse:Created>2018-08-28T08:03:40.749Z</wsse:Created>
</wsse:UsernameToken>
</o:Security>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<EnvioFacturaElectronicaPeticion xmlns="http://www.dian.gov.co/servicios/facturaelectronica/ReportarFactura">
<NIT><!--Removed--></NIT>
<InvoiceNumber>980000000</InvoiceNumber>
<IssueDate>2018-08-28T19:00:00</IssueDate>
<Document>UEsDBBQAAAAIAPBkHE3djKx2hwgAAEcdAAAeAAAAZmFjZV9mMDgxNjAwMjgzNDAwM0E2OTl.....

Вот что я делаю:

public string GeneraHeaderSOAP()
{
    const string apiUrl = "https://facturaelectronica.dian.gov.co/habilitacion/B2BIntegrationEngine/FacturaElectronica",
    apiUserName = "Username";

    string Password = "Password";
    string apiPassword = GetPassword(Password);

    EndpointAddress endpointAddress = new EndpointAddress(new Uri(apiUrl));

    SecurityBindingElement securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
    securityElement.AllowInsecureTransport = false;
    securityElement.EnableUnsecuredResponse = true;
    securityElement.IncludeTimestamp = false;

    TextMessageEncodingBindingElement encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
    HttpsTransportBindingElement transportElement = new HttpsTransportBindingElement();

    CustomBinding binding = new CustomBinding(securityElement, encodingElement, transportElement);

    //basic prueba
    BasicHttpSecurityMode securityMode = new BasicHttpSecurityMode();
    BasicHttpBinding binding2 = new BasicHttpBinding(securityMode);

    // Then assign username and password based on the proxy. For example -
    //var remoteAddress = new EndpointAddress("");
    WSDian.facturaElectronicaPortNameClient service = new WSDian.facturaElectronicaPortNameClient(binding, endpointAddress);
    //WSDian.facturaElectronicaPortNameClient service = new WSDian.facturaElectronicaPortNameClient(binding2, endpointAddress);
    service.ClientCredentials.UserName.UserName = apiUserName;
    service.ClientCredentials.UserName.Password = apiPassword;
    var Obtnonce = GetNonce();
    byte[] archivo = FileToByteArray(@"c:\temp\ws_f0816002834000000000A.zip");

    service.Open();

    WSDian.EnvioFacturaElectronica enviofactura = new WSDian.EnvioFacturaElectronica();

    enviofactura.NIT = "816006634";
    enviofactura.InvoiceNumber = "10";
    enviofactura.IssueDate = Convert.ToDateTime("2018-01-01 05:00:00");
    enviofactura.Document = archivo;

    //temporal

    WSDian.EnvioFacturaElectronicaPeticion envioFacturaElectronicaPeticion = new WSDian.EnvioFacturaElectronicaPeticion();
    WSDian.EnvioFacturaElectronicaRespuesta envioFacturaElectronicaRespuesta = new WSDian.EnvioFacturaElectronicaRespuesta();
    WSDian.AcuseRecibo acuseRecibo = new WSDian.AcuseRecibo();
    WSDian.ReceivedInvoice receivedInvoice = new WSDian.ReceivedInvoice();
    WSDian.facturaElectronicaPortNameClient facturaElectronicaPortNameClient = new WSDian.facturaElectronicaPortNameClient();

    envioFacturaElectronicaPeticion.EnvioFacturaElectronicaPeticion1 = enviofactura;
    var versionSoap = acuseRecibo.GetType();
    acuseRecibo = service.EnvioFacturaElectronica(envioFacturaElectronicaPeticion.EnvioFacturaElectronicaPeticion1);
}

Я добавляю ссылку на веб-сервис, чтобы использовать его, но когда я отлаживаю свой код, я получаю эту ошибку:

StatusCode = 400, StatusDescription = Неверный запрос.

Я не могу сгенерировать SOAP-запрос в соответствии со спецификациями, помогите.

Спасибо.

...