Next.js Discord

Discord Forum

Anybody can help me with the Soap Client

Unanswered
Dandie Dinmont Terrier posted this in #help-forum
Open in Discord
Dandie Dinmont TerrierOP
 Compiled /api/hks in 1307ms (439 modules)
SOAP istemcisi oluşturulurken hata: TypeError: Cannot read properties of undefined (reading 'createClientAsync')
    at createSoapClient (webpack-internal:///(rsc)/./app/utils/soapClient.ts:11:73)
    at getCountries (webpack-internal:///(rsc)/./app/services/hksService.ts:8:93)
    at GET (webpack-internal:///(rsc)/./app/api/hks/route.ts:11:99)


Gettin that kind of error while trying to retrieve some data from wsdl api

18 Replies

please translate the err message from soap lang to english
And send code
Dandie Dinmont TerrierOP
Compiled /api/hks in 1307ms (439 modules) Error creating SOAP client: TypeError: Cannot read properties of undefined (reading 'createClientAsync') at createSoapClient (webpack-internal:///(rsc)/./app/utils/soapClient.ts:11:73) at getCountries (webpack-internal:///(rsc)/./app/services/hksService.ts:8:93) at GET (webpack-internal:///(rsc)/./app/api/hks/route.ts:11:99)


/api/hks/route.ts
import { NextRequest, NextResponse } from 'next/server';
import { getCountries } from '../../services/hksService';

export async function GET(req: NextRequest) {
    try {
        const countries = await getCountries();
        return NextResponse.json(countries);
    } catch (error) {
        return NextResponse.json({ error: 'Ülke listesi alınamadı' }, { status: 500 });
    }
}



/services/hksService.ts
import { createSoapClient } from '../utils/soapClient';

export const getCountries = async () => {
    const client = await createSoapClient();

    const args = {
        UserName: process.env.HKS_USERNAME,       // Ortam değişkenlerinden kullanıcı adı
        Password: process.env.HKS_PASSWORD,       // Ortam değişkenlerinden şifre
        ServicePassword: '!1QAZWSX',              // Test 
        Istek: {}                                // Ülke isteği boş bırakılabiliyor
    };

    try {
        const [result] = await client.GenelServisUlkelerAsync(args); // API çağrısı
        return result;
    } catch (error) {
        console.error('Ülke listesi alınırken hata:', error);
        throw error;
    }
};


/utils/soapClient.ts
import soap from 'soap';

const WSDL_URL = 'http://hks.hal.gov.tr/WebServices/GenelService.svc?wsdl';

export const createSoapClient = async () => {
    try {
        const client = await soap.createClientAsync(WSDL_URL);
        return client;
    } catch (error) {
        console.error('SOAP istemcisi oluşturulurken hata:', error);
        throw new Error('SOAP istemcisi oluşturulamadı');
    }
};


@"use php"
@Dandie Dinmont Terrier `Compiled /api/hks in 1307ms (439 modules) Error creating SOAP client: TypeError: Cannot read properties of undefined (reading 'createClientAsync') at createSoapClient (webpack-internal:///(rsc)/./app/utils/soapClient.ts:11:73) at getCountries (webpack-internal:///(rsc)/./app/services/hksService.ts:8:93) at GET (webpack-internal:///(rsc)/./app/api/hks/route.ts:11:99)` /api/hks/route.ts import { NextRequest, NextResponse } from 'next/server'; import { getCountries } from '../../services/hksService'; export async function GET(req: NextRequest) { try { const countries = await getCountries(); return NextResponse.json(countries); } catch (error) { return NextResponse.json({ error: 'Ülke listesi alınamadı' }, { status: 500 }); } } /services/hksService.ts import { createSoapClient } from '../utils/soapClient'; export const getCountries = async () => { const client = await createSoapClient(); const args = { UserName: process.env.HKS_USERNAME, // Ortam değişkenlerinden kullanıcı adı Password: process.env.HKS_PASSWORD, // Ortam değişkenlerinden şifre ServicePassword: '!1QAZWSX', // Test Istek: {} // Ülke isteği boş bırakılabiliyor }; try { const [result] = await client.GenelServisUlkelerAsync(args); // API çağrısı return result; } catch (error) { console.error('Ülke listesi alınırken hata:', error); throw error; } }; /utils/soapClient.ts import soap from 'soap'; const WSDL_URL = 'http://hks.hal.gov.tr/WebServices/GenelService.svc?wsdl'; export const createSoapClient = async () => { try { const client = await soap.createClientAsync(WSDL_URL); return client; } catch (error) { console.error('SOAP istemcisi oluşturulurken hata:', error); throw new Error('SOAP istemcisi oluşturulamadı'); } }; <@755810867878297610>
That means createClientAsync is not a property inside soap. in soapClient.ts
thats what the err is saying
Dandie Dinmont TerrierOP
can you check the soapClient.ts ?
Yes I did
the error means createClientAsync is not a property
Dandie Dinmont TerrierOP
idk what's wrong
Cannot read properties of undefined (reading 'createClientAsync'
maybe try import * as soap from "soap"
Dandie Dinmont TerrierOP
const client = await soap.createClientAsync(WSDL_URL);
different kind of error now
✓ Compiled /api/hks in 154ms (439 modules) Error creating SOAP client: AxiosError: unable to verify the first certificate
i guess i need to bypass ssl check
resolved?
Dandie Dinmont TerrierOP
@"use php" yeah solved but still can't reach to data properly
it's just errors and errors..