WsdlToPhp / PackageGenerator

Generates a PHP SDK based on a WSDL, simple and powerful, WSDL to PHP
https://providr.io
MIT License
426 stars 73 forks source link

How do you get the response <soap:Header> details #219

Closed knox2 closed 3 years ago

knox2 commented 4 years ago

How do I get the soap response header, currently the output only contains the soap response body. eg in the beloe example response im able to get DataFormLoadReply from soap:Body and not ResponseErrorHeader from soap:Header.

How can I access the details in soap:Header

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <ResponseErrorHeader xmlns="Blackbaud.AppFx.WebService.API.1">
      <Name>string</Name>
      <ErrorCode>GeneralError or AccessDenied or InvalidAppDatabaseName or InvalidRequest or BadWebConfig or DbTransactionOutOfSync or DbConnectionError or DataFormError or BadMetaData or ServiceExecutionError or BusinessProcessError or InvalidAPIUse or DatabaseRevisionMismatch or InvalidSiteInfoID or InvalidProductIsHash or ProductListNotLoaded or TimeoutError</ErrorCode>
      <ErrorText>string</ErrorText>
      <ExceptionDetails>string</ExceptionDetails>
      <RootRequestName>string</RootRequestName>
      <RequestProcessorName>string</RequestProcessorName>
      <DataFormErrorInfo>
        <ErrorCode>GeneralError or InvalidFieldID or InsufficientFields or InvalidFieldValue or ConcurrencyViolation or RecordNotFound or BBPSGatewayProcessingFailure</ErrorCode>
        <ErrorMsg>string</ErrorMsg>
        <InvalidFieldID>string</InvalidFieldID>
        <InvalidFieldReason>RequiredFldMissing or DataTooLong or InvalidDataFormat or ValueGreaterThanMax or ValueLessThanMin or DataNotUnique or InvalidCodeTableEntry or DBForeignKeyFailure or DBConstraintFailure or CustomException</InvalidFieldReason>
        <InvalidFormID>guid</InvalidFormID>
        <InvalidFieldCollectionFieldID>string</InvalidFieldCollectionFieldID>
        <InvalidFieldPath>string</InvalidFieldPath>
        <SQLErrorInfo WasRethrownByStandardHandler="boolean">
          <ErrorMessage>string</ErrorMessage>
          <ErrorNumber>int</ErrorNumber>
          <Severity>int</Severity>
          <State>int</State>
          <Procedure>string</Procedure>
          <LineNumber>int</LineNumber>
          <ReThrowingProcedure>string</ReThrowingProcedure>
          <IsConcurrencyError>boolean</IsConcurrencyError>
          <IsRecordSecurityPermissionError>boolean</IsRecordSecurityPermissionError>
          <Instance>int</Instance>
        </SQLErrorInfo>
      </DataFormErrorInfo>
    </ResponseErrorHeader>
  </soap:Header>
  <soap:Body>
    <DataFormLoadReply LastUpdated="dateTime" xmlns="Blackbaud.AppFx.WebService.API.1">
      <DataFormItem>
        <Values xmlns="bb_appfx_dataforms">
          <fv ID="string">
            <Value />
            <ValueTranslation>string</ValueTranslation>
          </fv>
          <fv ID="string">
            <Value />
            <ValueTranslation>string</ValueTranslation>
          </fv>
        </Values>
      </DataFormItem>
      <TSLong>long</TSLong>
      <FormID>guid</FormID>
      <MetaData>
        <FormDefinition FixedDialog="boolean" HideBackgroundPanel="boolean">
          <FormFields xmlns="bb_appfx_commontypes">
            <FormField xsi:nil="true" />
            <FormField xsi:nil="true" />
          </FormFields>
          <FormUIComponent FormUIComponentType="DefaultUI or CustomComponent" xmlns="bb_appfx_commontypes">
            <CustomComponentID xsi:nil="true" />
          </FormUIComponent>
          <WebUIComponent xmlns="bb_appfx_commontypes">
            <UIModel xsi:nil="true" />
            <WebUI xsi:nil="true" />
          </WebUIComponent>
          <FieldGroups xmlns="bb_appfx_commontypes">
            <FieldGroup xsi:nil="true" />
            <FieldGroup xsi:nil="true" />
          </FieldGroups>
          <Tabs xmlns="bb_appfx_commontypes">
            <Tab xsi:nil="true" />
            <Tab xsi:nil="true" />
          </Tabs>
          <UIFields xmlns="bb_appfx_commontypes">
            <FormField xsi:nil="true" />
            <FormField xsi:nil="true" />
          </UIFields>
          <UIActions xmlns="bb_appfx_commontypes">
            <UIAction xsi:nil="true" />
            <UIAction xsi:nil="true" />
          </UIActions>
        </FormDefinition>
        <FormMode>View or Edit or Add</FormMode>
        <HelpKey>string</HelpKey>
        <CodeTablePerms>
          <perm ID="guid" CodeTableName="string" AllowAdd="boolean" AllowUpdate="boolean" AllowDelete="boolean" />
          <perm ID="guid" CodeTableName="string" AllowAdd="boolean" AllowUpdate="boolean" AllowDelete="boolean" />
        </CodeTablePerms>
        <DuplicateRecordCheck SearchListID="guid" IdentifiedDuplicateActionCaption="string" IdentifiedDuplicateActionCaptionResourceKey="string" DuplicateResolutionHeaderCaption="string" DuplicateResolutionHeaderCaptionResourceKey="string" HideSelectButton="boolean" HideIgnoreButton="boolean" HideSearchResults="boolean">
          <DuplicateResolutionUIComponent FormUIComponentType="DefaultUI or CustomComponent" xmlns="bb_appfx_commontypes">
            <CustomComponentID xsi:nil="true" />
          </DuplicateResolutionUIComponent>
        </DuplicateRecordCheck>
        <FormHeader>string</FormHeader>
        <RecordType>string</RecordType>
        <ContextRecordType>string</ContextRecordType>
        <LastUpdatedSource />
        <CustomizedFields>
          <CustomFieldCharacteristics IsRequired="boolean" IsHidden="boolean">
            <FieldID>string</FieldID>
          </CustomFieldCharacteristics>
          <CustomFieldCharacteristics IsRequired="boolean" IsHidden="boolean">
            <FieldID>string</FieldID>
          </CustomFieldCharacteristics>
        </CustomizedFields>
      </MetaData>
      <DataFormAddIns>
        <ComponentIdentifier AssemblyName="string" ClassName="string">
          <StaticParameters xmlns="bb_appfx_commontypes">
            <ParameterList xsi:nil="true" />
          </StaticParameters>
        </ComponentIdentifier>
        <ComponentIdentifier AssemblyName="string" ClassName="string">
          <StaticParameters xmlns="bb_appfx_commontypes">
            <ParameterList xsi:nil="true" />
          </StaticParameters>
        </ComponentIdentifier>
      </DataFormAddIns>
      <DataFormExtensionLoadReplies>
        <DataFormExtensionLoadReply RenderStyle="Tab or AfterParent" TabCaption="string">
          <LoadReply LastUpdated="dateTime">
            <DataFormItem xsi:nil="true" />
            <TSLong>long</TSLong>
            <FormID>guid</FormID>
            <MetaData xsi:nil="true" />
            <DataFormAddIns xsi:nil="true" />
            <DataFormExtensionLoadReplies xsi:nil="true" />
            <SanitizedHtmlFields xsi:nil="true" />
          </LoadReply>
        </DataFormExtensionLoadReply>
        <DataFormExtensionLoadReply RenderStyle="Tab or AfterParent" TabCaption="string">
          <LoadReply LastUpdated="dateTime">
            <DataFormItem xsi:nil="true" />
            <TSLong>long</TSLong>
            <FormID>guid</FormID>
            <MetaData xsi:nil="true" />
            <DataFormAddIns xsi:nil="true" />
            <DataFormExtensionLoadReplies xsi:nil="true" />
            <SanitizedHtmlFields xsi:nil="true" />
          </LoadReply>
        </DataFormExtensionLoadReply>
      </DataFormExtensionLoadReplies>
      <SanitizedHtmlFields>
        <string>string</string>
        <string>string</string>
      </SanitizedHtmlFields>
    </DataFormLoadReply>
  </soap:Body>
</soap:Envelope>
mikaelcom commented 4 years ago

Only the soap body is retrievable by default using getResult method or as the method call, it’s the native PHP SoapClient class behaviour.

To fetch the soap header, you can use the special method getLastResponse(true), see https://github.com/WsdlToPhp/PackageBase#usage-2, true allows you to get a DomDocument PHP object so you can then use the native PHP methods from the DomDocument class such as getElementsByTagName and so on....

Let me know if it’s enough clear.

knox2 commented 4 years ago

Hi @mikaelcom , I found an easier way to get it.

I did the following:

  1. created a variable

protected $output_headers;

then changed the below (using an example):

From

$this->setResult($this->getSoapClient()->UpdateBulkOrder($parameters));
return $this->getResult();

To

$this->setResult($this->getSoapClient()->__soapCall("UpdateBulkOrder", [$parameters], [],null, $this->output_headers));
return $this->getResult();

Then I created a function

public function getOutputHeaders()
{
        return $this->output_headers;
}

$this->getResult() //Get result body

$this->getOutputHeaders() //Get result header

The header now displays okay and can be accessible just the same way as the body via methods created by the package

mikaelcom commented 4 years ago

You’re smarter than me! I never looked so far to the parameters and it’s a good one!

Can you confirm you get generated class instances? So you edited the generated Service class to handle it in the meantime?

Anyway I think it would be a good improvement to catch the output headers anytime and to provide the corresponding method to get them for cases like yours!

knox2 commented 4 years ago

Indeed I get the generated class instances for the header, I was shocked that it worked, when I accessed the headers I could easily navigate using generated class methods to get the values I wanted....and Yes I edited the generated service class and added the changes.

It just worked.

mikaelcom commented 4 years ago

Indeed I get the generated class instances for the header, I was shocked that it worked, when I accessed the headers I could easily navigate using generated class methods to get the values I wanted....and Yes I edited the generated service class and added the changes.

It just worked.

Great! Thanks for the info :)

knox2 commented 4 years ago

Hopefully it gets to the core......thanks

mikaelcom commented 4 years ago

Hi, could you try to generate your package using the feature/issue-219 branch or the phars from:

Let me know then,

knox2 commented 4 years ago

Hi @mikaelcom,

I'll test it this week and give feedback

knox2 commented 3 years ago

Hi @mikaelcom , sorry I've taken long to respond. Work has been really busy, I finally managed to test it...It works perfectly...Thanks so much