• 星融 潘 6
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
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?
Backgroud: I need access SAP from salesforce. SAP server is in  company intranet. Salesforce cloud is in outer net.
There is a gateway between SAP server and Salesforce cloud.
So first,I need a http request to login gateway with company's username and  password. The the gateway will respones 3 cookies.
I should include  these 3 cookies when I access the sap SOAP webservice.
I'm able to access SAP SOAP webservice in .Net as below.
//Creat request to login gateway
            System.Net.HttpWebRequest request = (HttpWebRequest)WebRequest.Create("gateway/login");
            String PostString = "user=myusername&password=mypassword&btn_login=Logn-On&idpid=at_hp";
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            byte[] buffer = encoding.GetBytes(PostString);
            request.AllowAutoRedirect = false;
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "POST";
            request.CookieContainer = new CookieContainer();
            Stream reqstr = request.GetRequestStream();
            reqstr.Write(buffer,0,buffer.Length);
            reqstr.Close();
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//get the respones cookies
            CookieCollection mycookies = response.Cookies;
// Create sap SOAP webservice
            Z_WEBSERVICESService SAPWSDL = new Z_WEBSERVICESService();
// use the cookies
            SAPWSDL.CookieContainer = new CookieContainer();
            SAPWSDL.CookieContainer.Add(mycookies[0]);
            SAPWSDL.CookieContainer.Add(mycookies[1]);
            SAPWSDL.CookieContainer.Add(mycookies[2]);
//set the credential
            System.Net.NetworkCredential cred = new System.Net.NetworkCredential();
            cred.UserName = "SAPusername";
            cred.Password = "SAPpassword";
            SAPWSDL.Credentials = cred;
//access SAP webservice.
            string xx = SAPWSDL.Z_WEBSERVICES();
I have some qustion about how to convert this code to apex.
1 In Apex, how to use cookies?
2 how to set AllowAutoRedirect = false? If Redirect,I can't get respones with cookies.
3 When use SOAP in Apex,is there a way to set cookies and credential.

I have down load the XML file  enterprise.wsdl from salesforce.
I want to cteate a enterprise service in SAP,when I active the service,it show error message "Recursions must be eliminated".
Then I found below code result the error.
<complexType name="DataCategory">
                <sequence>
                    <element name="childCategories" type="tns:DataCategory" minOccurs="0" maxOccurs="unbounded"/>
                    <element name="label" type="xsd:string"/>
                    <element name="name" type="xsd:string"/>
                </sequence>
</complexType>


Example:
A packing unit is described by its length, width, height, and content. The content can also consist of packing units.
<complexType name="PackingUnit">
  <sequence>
    <element name="length"  type="int"/>
    <element name="width"   type="int"/>
    <element name="height"  type="int"/>
    <element name="content" type="PackingUnit"
maxOccurs="unbounded"/>
  </sequence>
</complexType>

In ABAP, recursively defined structures are not possible.

Currently, the only solution is to replace a recursive reference by a reference to the data element XSDANY, so that the structure looks like this:
  Dictionary structure PACKING_UNIT
    Field LENGTH  TYPE INT4
    Field WIDTH   TYPE INT4
    Field HEIGHT  TYPE INT4
    Field CONTENT TYPE PACKING_UNIT_CONTENT_TAB
  Dictionary table type PACKING_UNIT_CONTENT_TAB
    Line type XSDANY (not TYPE PACKING_UNIT)

How can I deal with this? I try to change XML file,but make more error.
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?
I have down load the XML file  enterprise.wsdl from salesforce.
I want to cteate a enterprise service in SAP,when I active the service,it show error message "Recursions must be eliminated".
Then I found below code result the error.
<complexType name="DataCategory">
                <sequence>
                    <element name="childCategories" type="tns:DataCategory" minOccurs="0" maxOccurs="unbounded"/>
                    <element name="label" type="xsd:string"/>
                    <element name="name" type="xsd:string"/>
                </sequence>
</complexType>


Example:
A packing unit is described by its length, width, height, and content. The content can also consist of packing units.
<complexType name="PackingUnit">
  <sequence>
    <element name="length"  type="int"/>
    <element name="width"   type="int"/>
    <element name="height"  type="int"/>
    <element name="content" type="PackingUnit"
maxOccurs="unbounded"/>
  </sequence>
</complexType>

In ABAP, recursively defined structures are not possible.

Currently, the only solution is to replace a recursive reference by a reference to the data element XSDANY, so that the structure looks like this:
  Dictionary structure PACKING_UNIT
    Field LENGTH  TYPE INT4
    Field WIDTH   TYPE INT4
    Field HEIGHT  TYPE INT4
    Field CONTENT TYPE PACKING_UNIT_CONTENT_TAB
  Dictionary table type PACKING_UNIT_CONTENT_TAB
    Line type XSDANY (not TYPE PACKING_UNIT)

How can I deal with this? I try to change XML file,but make more error.