Add Web Reference

Hi All,

There is a web service ( http://pttws.ptt.gov.tr/GonderiHareketV2Test/services/Sorgu?wsdl ) they ask me that web service should be described with “Add Web Reference” from VS and it uses HTTPS instead of HTTP. Is that possible with AX and if yes how?

Hi,

You can select web service reference from the inbound or outbound port which one you are referring to Visual studio add web reference from the WSDL URL field.

Please describe more on your requirements.

Regards

Yes, creating a class library in Visual Studio and using Add Service Reference is how external services are consumed in AX 2012. Check out Walkthrough: Calling an External Web Service from X++. HTTPS shouldn’t be any problem either, if they expose the service via HTTPS.

I could create service with “Add Web Reference”, but (BTW WSDL address not at upper here, this; https://pttws.ptt.gov.tr/PttVeriYuklemeTest/services/Sorgu?wsdl ).

There were SorguPortTypeClient and I was using that:

clientType = CLRInterop::getType(“PTT.PTTservice.SorguPortTypeClient”);

but it isn’t show anymore and I tried to use like:

clientType = CLRInterop::getType(“PTT.tr.gov.ptt.pttws.SorguPortTypeClient”);

and gives error:

System.InvalidOperationException: Type PTT.tr.gov.ptt.pttws.Sorgu is not a service client. It does not implement a service contract.

I supposed using this type of web services should be different but how?

My code:

CLRObject clientType;

PTT.tr.gov.ptt.pttws.InputDongu2[] dngList = new PTT.tr.gov.ptt.pttws.InputDongu21;
PTT.tr.gov.ptt.pttws.InputDongu2 dng = new PTT.tr.gov.ptt.pttws.InputDongu2();
PTT.tr.gov.ptt.pttws.Sorgu service;
PTT.tr.gov.ptt.pttws.Input2 input = new PTT.tr.gov.ptt.pttws.Input2();
PTT.tr.gov.ptt.pttws.GondericiBilgi gnd = new PTT.tr.gov.ptt.pttws.GondericiBilgi();
PTT.tr.gov.ptt.pttws.Output2 output;
str st;
#OCCRetryCount
System.Exception ex;

str outResult;
String10 outflag,errorNum;
smmParametersTable smmParametersTable = smmParametersTable::find();
System.Int64 i;

System.Type nullableType = System.Type::GetType(‘System.Nullable`1[System.Int32]’);
System.Object decimalValue;
System.Object[] paramValues = new System.Object1;
CLRObject nullableValue;

try
{
new InteropPermission(InteropKind::ClrInterop).assert();

// clientType = CLRInterop::getType(“PTT.tr.gov.ptt.pttws.SorguPortTypeClient”);
clientType = CLRInterop::getType(“PTT.tr.gov.ptt.pttws.Sorgu”);

service = AifUtil::createServiceClient(clientType);

I just already used that way dozen times with different web services. This one ( https://pttws.ptt.gov.tr/PttVeriYuklemeTest/services/Sorgu?wsdl ) doesn’t works like that. After Add service Reference, have to press “Advanced”, “Add Web Reference” they said.

When using there is no clientType = CLRInterop::getType("… and service = AifUtil::createServiceClient(… lines. Actually I don’t know what means all of these but with this service seem it works different. They just said that “This’s not a service reference, web reference” .

Now I’m just getting empty respond at last line. I don’t know:

CLRObject clientType;

PTT.tr.gov.ptt.pttws.InputDongu2[] dngList = new PTT.tr.gov.ptt.pttws.InputDongu21;
PTT.tr.gov.ptt.pttws.InputDongu2 dng = new PTT.tr.gov.ptt.pttws.InputDongu2();
PTT.tr.gov.ptt.pttws.Sorgu service = new PTT.tr.gov.ptt.pttws.Sorgu();
PTT.tr.gov.ptt.pttws.Input2 input = new PTT.tr.gov.ptt.pttws.Input2();
PTT.tr.gov.ptt.pttws.GondericiBilgi gnd = new PTT.tr.gov.ptt.pttws.GondericiBilgi();
PTT.tr.gov.ptt.pttws.Output2 output;
PTT.tr.gov.ptt.pttws.kabulEkle2CompletedEventArgs a;
str st;

#OCCRetryCount
System.Exception ex;

str outResult;
String10 outflag,errorNum;
smmParametersTable smmParametersTable = smmParametersTable::find();
System.Int64 i;

System.Type nullableType = System.Type::GetType(‘System.Nullable`1[System.Int32]’);
System.Object decimalValue;
System.Object[] paramValues = new System.Object1;
CLRObject nullableValue;

try
{
new InteropPermission(InteropKind::ClrInterop).assert();

input.set_kullanici(“PttWs”);
input.set_gonderiTip(“NORMAL”);
input.set_gonderiTur(“KARGO”);
input.set_musteriIdSpecified(true);

if (this.DeliveryType == ETGCustRequestDeliveryType::Consumer)
{
decimalValue = System.Convert::ToInt32(smmParametersTable.SNBPTTinUserPers);
paramValues.SetValue(decimalValue, 0);
nullableValue = System.Activator::CreateInstance(nullableType, paramValues);
input.set_musteriId(nullableValue);
input.set_sifre(smmParametersTable.SNBPTTinUserPasswordPers);
}
else
{
decimalValue = System.Convert::ToInt32(smmParametersTable.SNBPTTinUserComm);
paramValues.SetValue(decimalValue, 0);
nullableValue = System.Activator::CreateInstance(nullableType, paramValues);
input.set_kullanici(nullableValue);
input.set_sifre(smmParametersTable.SNBPTTinUserPasswordComm);
}

dng.set_aAdres(CompanyInfo::findDataArea(curext()).addressing().Street);
dng.set_aliciAdi(CompanyInfo::findDataArea(curext()).Name);
dng.set_aliciIlAdi(CompanyInfo::findDataArea(curext()).addressing().State);
dng.set_aliciIlceAdi(CompanyInfo::findDataArea(curext()).addressing().City);
dng.set_barkodNo(this.CargoShipmentId);

gnd.set_gonderici_adi(this.DirPartyTable().Name);
gnd.set_gonderici_adresi(this.smmLeadTable().ETGAddress);
gnd.set_gonderici_il_ad(this.smmLeadTable().ETGPartyState);
gnd.set_gonderici_ilce_ad(this.smmLeadTable().ETGPartyCounty);
gnd.set_gonderici_telefonu(this.smmLeadTable().ETGPhoneNumber);
gnd.set_gonderici_email(this.smmLeadTable().ETGEmail);

dng.set_gondericibilgi(gnd);

dngList.SetValue(dng,0);
input.set_dongu(dngList);

output = service.kabulEkle2(input);

All right, it seems that they use some legacy, pre-WCF stuff and therefore you’re forced to use the old and deprecated approach.

I obviously have no access to your database, so I can’t run your code. I also prefer doing things one by one, therefore I’m testing it first in Visual Studio before integrating it to AX. Note that you can greatly simplify your code if you keep it in the class library. Like this:

InputDongu2 dongu = new InputDongu2()
{
    aAdres = "A street"
};

Input2 input = new Input2()
{
    kullanici = "Ptts",
    gonderiTip = "NORMAL",
    gonderiTur = "KARGO",
    musteriIdSpecified = true,
    dongu = new InputDongu2[] { dongu }
};

using (Sorgu client = new Sorgu())
{
    Output2 o2 = client.kabulEkle2(input);
}

Creating Sorgu instance inside using makes sure that resources are released when when they’re not indeed anymore.

Unfortunately I know nothing about the service operation, therefore I don’t know what parameters it expects to work.