none
how to make a WCF service that can read a raw xml SOAP request RRS feed

  • Question

  • New to WCF. I am using c# What would the service code look like to grab this

    The code sending looks like this

        static void Main(string[] args)
        {
            using (var client = new WebClient())
            {
                // read the raw SOAP request message from a file
                var data = File.ReadAllText("request.xml");
                // the Content-Type needs to be set to XML
                client.Headers.Add("Content-Type", "text/xml;charset=utf-8");
                // The SOAPAction header indicates which method you would like to invoke
                // and could be seen in the WSDL: <soap:operation soapAction="..." /> element
                client.Headers.Add("SOAPAction", "\"http://www.example.com/services/ISomeOperationContract/GetContract\"");
                var response = client.UploadString("http://example.com/service.svc", data);
                Console.WriteLine(response);
            }
        }


    www.helixpoint.com

    Monday, May 1, 2017 5:51 PM

All replies

  • You could develop a WCF Service with the corresponding SOAP request and SOAPAction.

    Here are simple steps:

    1. Create a simple service

    IService.cs
        [ServiceContract]
        public interface IService1
        {
    
            [OperationContract]
            string GetData(int value);
    }
    Service.cs
        public class Service1 : IService1
        {
            public string GetData(int value)
            {
                return string.Format("You entered: {0}", value);
            }
        }

    2.Run the Service, and the service url is “http://localhost:30983/Service1.svc”

    3.Call from client

                using (WebClient client = new WebClient())
                {
                    var data = System.IO.File.ReadAllText("request.xml");
                    client.Headers.Add("Content-type", "text/xml;charset=utf-8");
                    client.Headers.Add("SOAPAction", "http://tempuri.org/IService1/GetData");
                    var response = client.UploadString("http://localhost:30983/Service1.svc", data);
                    Console.WriteLine(response);
                }

    4.request.xml

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Body>
        <GetData xmlns="http://tempuri.org/">
          <value>123</value>
        </GetData>
      </s:Body>
    </s:Envelope>



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 2, 2017 3:27 AM
  • I tried this and it works nicely, but how would I read soap like this..... <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:DLA:InterfaceStage"> <soapenv:Header> <urn:AuthenticationInfo> <urn:userName>?</urn:userName> <urn:password>?</urn:password> <urn:authentication>?</urn:authentication> <urn:locale>?</urn:locale> <urn:timeZone>?</urn:timeZone> </urn:AuthenticationInfo> </soapenv:Header> <soapenv:Body> <urn:Create> <urn:TransactionType>New</urn:TransactionType> <urn:var_SPOEID>REQ000000086331</urn:var_SPOEID> <urn:Attachment1_attachmentName>?</urn:Attachment1_attachmentName> <urn:Attachment1_attachmentData>cid:388621466977</urn:Attachment1_attachmentData> <urn:Attachment1_attachmentOrigSize>?</urn:Attachment1_attachmentOrigSize> <urn:Attachment2_attachmentName>?</urn:Attachment2_attachmentName> <urn:Attachment2_attachmentData>cid:233028653334</urn:Attachment2_attachmentData> <urn:Attachment2_attachmentOrigSize>?</urn:Attachment2_attachmentOrigSize> <urn:Attachment3_attachmentName>?</urn:Attachment3_attachmentName> <urn:Attachment3_attachmentData>cid:614853385710</urn:Attachment3_attachmentData> <urn:Attachment3_attachmentOrigSize>?</urn:Attachment3_attachmentOrigSize> <urn:var_RequesterFirstName>Joe</urn:var_RequesterFirstName> <urn:var_RequesterMiddleName>M</urn:var_RequesterMiddleName> <urn:var_RequesterLastName>User</urn:var_RequesterLastName> <urn:var_RequesterEmail>JoeUser@dla.mil</urn:var_RequesterEmail> <urn:Requester_Organization>5</urn:Requester_Organization> <urn:Requester_Location>13</urn:Requester_Location> <urn:var_RequesterEDIPI>1234567890</urn:var_RequesterEDIPI> <urn:var_SubmitterLastName>Doe</urn:var_SubmitterLastName> <urn:var_SubmitterFirstName>Jane</urn:var_SubmitterFirstName> <urn:var_SubmitterEmail>JaneDoe@dla.mil</urn:var_SubmitterEmail> <urn:var_SubmitterMiddleName>S</urn:var_SubmitterMiddleName> <urn:var_SubmitterOrg>13</urn:var_SubmitterOrg> <urn:var_SubmitterLocation>8</urn:var_SubmitterLocation> <urn:var_SubmitterEDIPI>1234567891</urn:var_SubmitterEDIPI> <urn:var_RecordType>ITCR</urn:var_RecordType> <urn:var_CapOfficeMission>To align IT services delivered to customers with the needs of the business</urn:var_CapOfficeMission> <urn:var_RequirementBackground>New Service Management Fulfillment Platform</urn:var_RequirementBackground> <urn:var_ProblemStatement>Example Problem Statement</urn:var_ProblemStatement> <urn:var_ProposedSolution>Example Proposed Solution</urn:var_ProposedSolution> <urn:var_ProposedSolutionDetails>This proposed solution will require X, X, and X</urn:var_ProposedSolutionDetails> <urn:var_CapExistingSolution>Existing solutions do not offer the requires functionality to meet the business needs</urn:var_CapExistingSolution> <urn:var_CapType>24</urn:var_CapType> <urn:var_CapRequirementBusinessNeed>Business Need 1</urn:var_CapRequirementBusinessNeed> <urn:var_CapRequirementBusinessNeed2>Business Need 2</urn:var_CapRequirementBusinessNeed2> <urn:var_CapRequirementBusinessNeed3>Business Need 3</urn:var_CapRequirementBusinessNeed3> <urn:var_CapRequirementBusinessNeed4>Business Need 4</urn:var_CapRequirementBusinessNeed4> <urn:var_CapRequirementBusinessNeed5>Business Need 5</urn:var_CapRequirementBusinessNeed5> <urn:var_CapFundingInformation>This is a test funding information excerpt</urn:var_CapFundingInformation> <urn:var_InfoOnly>No</urn:var_InfoOnly> <urn:var_CapWasCostEstimated>Yes</urn:var_CapWasCostEstimated> <urn:var_CapFunded>1</urn:var_CapFunded> <urn:var_CapTechnicalSupport>Support will be provided by a new support group utilizing Remedy ITSM</urn:var_CapTechnicalSupport> <urn:var_CapEstimatedCost>999999999999</urn:var_CapEstimatedCost> </urn:Create> </soapenv:Body> </soapenv:Envelope>

    www.helixpoint.com

    Tuesday, May 2, 2017 12:26 PM
  • It seems you misunderstood WCF Service.

    When you send a request which follows the wsdl from WCF Service, the SOAP request will be formatted to the corresponding object. If the request did not meet the scheme of WCF Service, it would not work. That is the reason I followed create service, send SOAP request from client in my first reply.

    If you want to send SOAP request to WCF Service, you need to create a service which accepts the object you want to send from client to service, and then pay attention to the SOAP request, implement from WebClient.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 4, 2017 6:34 AM