function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
星融 潘 6星融 潘 6 

Superclass of Generated class by WSDL.XML

Hi guys,
Firstly,I'm new guy of apex.
Now I'm dealing with some webservice problem
I need access the .net webservice from apex. I imported a WSDL file and generated a class.
I just want to know what's the superclass for all generated class by WSDL. Because in my case, before you access .net webservice,I need add some imformation in http header like bellow. And I don't want write this code before callout for every generated class by WSDL.So I want a method to add httpheader for all generated class by WSDL.
NotNetFunctions.Z_WEBSERVICESPortType C= NEW NotNetFunctions.Z_WEBSERVICESPortType();
        Blob headerValue = Blob.valueOf('username' +':' +'password');
        String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
        C.inputHttpHeaders_x = new Map<String, String>();
        c.inputHttpHeaders_x.put('Cookie',cookies);
        c.inputHttpHeaders_x.put('Authorization', authorizationHeader);

In .net there is supper class name 'SoapHttpClientProtocol' for all generated class by WSDL.if I want to add httpheader for all generated class,it's very easy as below.
public static void AddHttpHeader(SoapHttpClientProtocol WebService) { 
          
            WebService.CookieContainer = new CookieContainer();
            WebService.CookieContainer.Add(mycookies[0]);
            WebService.CookieContainer.Add(mycookies[1]);
            WebService.CookieContainer.Add(mycookies[2]);
            //set the credential
            System.Net.NetworkCredential cred = new System.Net.NetworkCredential();
            cred.UserName = "USERNAME";
            cred..Password = "PASSWORD";
            WebService.Credentials = cred;
        }

Publick static void test(){
            Z_WEBSERVICESPortType SpecificWebservice = new Z_WEBSERVICESPortType.
            this.AddHttpHeader(SpecificWebservice);
}

In apex,is there a class like SoapHttpClientProtocol?
kaustav goswamikaustav goswami
In apex you will not be able to access the super class of the genearted stub from wsdl.

If you want to add http headers you will have to populate the http headers map for the operation that you invoke.
Something like :

stub.inputHttpHeaders_x.put('Cookie', 'name=value');

You can have a common piece of code that you can include in the code to populate these values.

Thanks,
Kaustav

星融 潘 6星融 潘 6
Hi Kaustav,
thanks for help.
How to include common code into class method?
kaustav goswamikaustav goswami
I think the best way to do it will be store the parameter values in a custom settings.

Say you create a custom setting called WEb Servoce Basics.

In that custom setting create two fields - name/value pair.

Then create the records in that custom setting:

Example:

NAME: authorization header VALUE : encoded header value

Then inyour code develop a utility method that would fetch these values from the custom setting populate them in a map and return you the map.

Now when doing the callout call this utility method and assign the retuned map to the httpinputheaders_x map and carry out the callout.

Thanks,
Kaustav
星融 潘 6星融 潘 6
Thanks again.
Yes, you are right, that's what I'm doing.
But, is there a better way to do this?
You see,if you have 10 webservice method,you need add the same code to add httpheader beforce callout for every single webservice method.
I just want a common method like this.
Z_WEBSERVICESPortType SpecificWebservice = new Z_WEBSERVICESPortType.
this.AddHttpHeader(SpecificWebservice);
is it possible?