response content type

hi, I'm not very practical, I have a proxy class automatically generated via "add web reference" with the wsdl file in my C# project, this class in wso2 works, the company would like to try apigee but doing a test I get an error, the soap message should have the content type "text/xml" but in the response it is instead "application/xml" and it gives me an error. What i can do ?

2 5 156
5 REPLIES 5

Hello @Bodrus ,

Modifying response content-type is what you're looking for then the below Assign-Message policy snippet will help for you. Please refer the detailed documentation for assign-message-policy 

 

<AssignMessage name="modify-response">
  <Set>
    <Headers>
      <Header name="Content-Type">text/xml</Header>
    </Headers>
  </Set>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <AssignTo createNew="false" type="response"></AssignTo>
</AssignMessage>

 

hi chrismca73  , thanks for your reply.

Now I understand the problem, the class autogenerated via the webreference automatically adds the following content-type: text/xml; charset=utf-8 with a space between the content and the charset. Apigee rejects this message giving me Soap message error , now instead of the webreference I used the service reference and I modified the inner channl passing text/xml;charset=utf-8 for the content type. Now it works, I'm sorry to have to manually call all the methods giving up the autogenerated class, in fact using it even changing the content type in the webrequest after overwriting it nothing happens.


@Bodrus wrote:

the soap message should have the content type "text/xml" but in the response it is instead "application/xml" and it gives me an error. What i can do ?


Chris is right that you can use AssignMessage to set the content-type header to whatever is required.  If you attach the policy in the REQUEST flow, then the request that the proxy sends  to the upstream will use that header. If you attach the policy iin the RESPONSE flow then the proxy will alter the  response it sends to the original caller, to use that header.  Either might be appropriate for you. 

But

text/xml and application/xml are aliases.   They should both work. Per IETF RFC 7303, they are equivalent and systems should accept either.  A system that insists on text/xml and rejects application/xml is unnecessarily brittle and should be altered.  Even so, your Apigee proxy can adapt the payload to fit with an outdated system. 


@Bodrus wrote:

Apigee rejects this message giving me Soap message error ,


Can you explain what you mean by this? can you be more  specific about what you see?  It sounds like you have an Apigee proxy configured to handle this request;  In that proxy, where does this "reject" occur?  How do you observe the "reject"?  Is there a specific policy you are using that causes the "reject" ?  A Condition?    Can you share a debugsession? 

yes you're right , the company ha configured this proxy on apigee.

The problem is in the space between contenttype and chareset , with autogerated proxy i'm not able to change the charset  , but i'm new to api programming maybe is for this.

the charset set by the autogenerated class is always text/xml; charset=utf-8 even if I try to override it without the space.

Immagine.jpg

Notice the space before the semicolon. This way I get the following error from apigee

 

The content of the response detected by the client is of type 'application/xml', instead of the expected 'text/xml'. Request failed with empty response.

this is the response message

Message stage: SOAP RESPONSE (AfterSerialize)
Exception thrown? No

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getMailRoomQryTbPAnno xmlns="it.groupama.dss.mailroom"><anno>2024</anno><filterQuery>where 1 = 0 </filterQuery></getMailRoomQryTbPAnno></soap:Body></soap:Envelope>
*************************************************
Web service: https://api-svil.groupama.it/gestioneMailRoom/1
Web method: urn:getMailRoomQryTbPAnno
Called at 21/03/2024 20:48:34
Message stage: SOAP REQUEST (BeforeDeserialize)

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"><env:Header/><env:Body><env:Fault><env:Code><env:Value>Error</env:Value>
</env:Code><env:Reason><env:Text xml:lang="en-US">
Invalid SOAP Message
</env:Text>
</env:Reason>
</env:Fault>
</env:Body>
</env:Envelope>

 

to solve the problem after many research and many many attemts  i added this class

Immagine1.jpg

 

Immagine.jpg

but in this way i must write a wrapper for each method , no more override webrequest ..

 

MailRoomPortTypeClient is the autogenerated proxy class after addin service reference and passing wsdl.

previously using the class generated via webreference I could automatically intercept and overwrite the webrequest

i found a best way , with soap extension i can access to soap message and here i can set te contentype to desidered one with no space betwen contenttype e charaterset , i dont know if this is a apigee's problem or else .. finally i found the solution.