locked
Send xml in Post body in WCF-WebHttp adaptor RRS feed

  • Question

  • Hi,

    I'm trying to send xml received from a response to Post action of a restfull service in WCF_WebHttp adaptor,

    can anyone guide me on how could i do this.

    thanks

    noor syed

    Saturday, October 22, 2016 12:59 PM

Answers

All replies

  • Hi Noor,

    Refer the thread: https://social.msdn.microsoft.com/Forums/en-US/f7d91dec-1275-412e-a3fe-17885ba1c962/biztalk-wcf-webhttp-post-method-along-with-example?forum=biztalkgeneral

    Are you able to invoke the POST operation outside BizTalk using something like Fiddler?

    If yes, getting it to work in BizTalk is simple. You can refer this sample.

    You will need the schemas for the Post operation. 

    And specify the HTTP verb as POST in the WCF-WebHttp adapter config-

    image

    Regarding the schemas for the POST oepration-

    1) If web API uses JSON payloads-

    If you are using BizTalk 2013 R2, you can use the JSON schema wizard to create the XML schemas from your sample JSON request/response -

    https://msdn.microsoft.com/en-us/library/dn789171.aspx

    http://www.quicklearn.com/blog/2014/08/21/json-schemas-in-biztalk-server-2013-r2/

    If you are using an earlier version of BizTalk server, you can first generate the XML format for your JSON sample messages using something like this - http://codebeautify.org/jsontoxml. Once you have the sample XML request/response messages, you can easily create schemas using the Generate Schemas Wizard in a BizTalk project in Visual Studio.

    2) If web API uses XML format messages-

    Just use the sample XML request/response messages from Fiddler and you can create the schemas using the Generate Schemas Wizard in a BizTalk project in Visual Studio.


    Rachit Sikroria (Microsoft Azure MVP)

    Saturday, October 22, 2016 1:39 PM
    Moderator
  • The short answer (totally serious), you just do it.

    The WCF-WebHttp Adapter isn't very fussy about a lot of things so if you have Xml in the Body of the outgoing Message, it will POST Xml to the configured Address.

    You best option, just try it.  If you get any errors, we can help with those.

    Saturday, October 22, 2016 9:09 PM
    Moderator
  • Hi ,

    I have tried, i have an xml in the body but it isn't being passed to Post action, thought it is supposed to

    below is the configuration in biztalk

    i have also given below Outbound Http Headers in Messages tab

    Accept:application/xml
    Content-Type:application/xml

    when i call it, i'm not getting XML as an object in post method parameter

    the acknkowledgment class looks like below

    and the xml schema looks like below

    <?xml version="1.0" encoding="utf-16"?>
    <xs:schema xmlns="MazikCareService.Core.Models.HL7" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:ns1="https://Birch.HL7.Schemas.Api.MessageControl" xmlns:ns0="https://Birch.HL7.Schemas.Api.AcknowledgmentCode" targetNamespace="MazikCareService.Core.Models.HL7" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:annotation>
        <xs:appinfo>
          <b:imports>
            <b:namespace prefix="ns0" uri="https://Birch.HL7.Schemas.Api.AcknowledgmentCode" location=".\AcknowledgmentCode.xsd" />
            <b:namespace prefix="ns1" uri="https://Birch.HL7.Schemas.Api.MessageControl" location=".\MessageControl.xsd" />
          </b:imports>
        </xs:appinfo>
      </xs:annotation>
      <xs:element name="Acknowledgment">
        <xs:annotation>
          <xs:appinfo>
            <b:properties>
              <b:property name="ns0:Code" xpath="/*[local-name()='Acknowledgment' and namespace-uri()='MazikCareService.Core.Models.HL7']/*[local-name()='Code' and namespace-uri()='']" />
              <b:property name="ns1:MessageControlId" xpath="/*[local-name()='Acknowledgment' and namespace-uri()='MazikCareService.Core.Models.HL7']/*[local-name()='MessageControlId' and namespace-uri()='']" />
            </b:properties>
          </xs:appinfo>
        </xs:annotation>
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Code" type="xs:string" />
            <xs:element name="MessageControlId" type="xs:string" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>



    i'm kind of stuck here, trying to figure out what's going wrong, i would appreciate if you could do some help and guide me where i'm going wrong



    Monday, October 24, 2016 10:09 AM
  • Can you describe what is actually happening?  Output, error, different content?

    It really is that simple.

    Monday, October 24, 2016 12:15 PM
    Moderator
  • the port from which i'm making call to Post action receives an xml whose schema i shared,

    i have checked the xml is received successfully, but isn't being passed as Post parameter,

    i believe the endpoint and url mapping take the received xml in the body of post action automatically, correct me if i'm wrong

    Monday, October 24, 2016 2:27 PM
  • Unless you actually using it, you don't really need anything in the Mapping section.

    Did you try just POST?  That's about as generic as you can get.

    Monday, October 24, 2016 3:26 PM
    Moderator
  • ok just Post in URL mapping, then the url should go into the endpoint address ?
    Tuesday, October 25, 2016 7:24 AM
  • Your BTSOperation Mapping is missing the Name attribute.. The Name should be the same nae as the orchestration logical operation Name.

    Else just have POST in the HTTP Mapping section and have ur url configured fully.


    Pi_xel_xar

    Blog: My Blog

    BizTalkApplicationDeploymentTool: BizTalk Application Deployment Tool/

    Tuesday, October 25, 2016 7:30 AM
    Answerer
  • tried this

    but still getting null

    Tuesday, October 25, 2016 7:32 AM
  • Hi Noor,

    make sure of following things

    1) Your opertain name in The BTS action mapping xmlblob shoul match the operation name of the logical port in the orchesration.

    2) have you tested the api using soap Ui tool,meaning can you confirm if it is indeed the issue with Biztalk or PAI,

    if the api is returning response to SOAP Ui then we can focus on the Biztalk part.

    regards


    Mandar Dharmadhikari

    Tuesday, October 25, 2016 7:51 AM
    Moderator
  • What is that code you're posting? SendAck?

    That's not a BizTalk thing.

    Tuesday, October 25, 2016 11:26 AM
    Moderator
  • i was trying to pass xml received on this port, also attached the schema of the same,

    just tried json encoder on the received pipeline in my custom pipeline and it magically worked,

    object and properties mapped and im getting values now.

    thanks everyone for your support and help, it did help, guide and encourage me

    Tuesday, October 25, 2016 12:34 PM