Luis Valencia
Luis Valencia

Reputation: 34028

How to call WCF service method from POSTMAN

I am trying to call a service using WCF endpoint. The WCF service is hosted on a Windows Service,

This is the config.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.diagnostics>  
    <sources>
      <source name="System.ServiceModel" propagateActivity="true" switchValue="All">
        <listeners>
          <add name="xmlTraceListener" />
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="All">
        <listeners>
          <add name="xmlTraceListener" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xmlTraceListener"
           type="System.Diagnostics.XmlWriterTraceListener"
           initializeData="C:\logwcf\Service.svclog" />
    </sharedListeners>
  </system.diagnostics>
  <system.web>
    <httpRuntime executionTimeout="90" />
  </system.web>
  <startup useLegacyV2RuntimeActivationPolicy="True">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
  </startup>
  <system.serviceModel>
  <diagnostics>
        <messageLogging logEntireMessage="true" 
                        logMalformedMessages="true" 
                        logMessagesAtServiceLevel="true" 
                        logMessagesAtTransportLevel="true">
          <filters>
            <clear/>
          </filters>
        </messageLogging>
      </diagnostics>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_Hostware" closeTimeout="00:10:30" openTimeout="00:10:30" receiveTimeout="00:10:30" sendTimeout="00:10:30" allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true" messageEncoding="Text">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="xx.ServicioDistribucion.AnalisisDatos.Servicios.CuentasCobrar" behaviorConfiguration="behaviorDistribucion">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Hostware" contract="xx.ServicioDistribucion.AnalisisDatos.Interfaces.ICuentasCobrar">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://xx.143.46.82:8733/xx.ServicioDistribucion.AnalisisDatos.Servicios.CuentasCobrar/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behaviorDistribucion">
          <serviceThrottling maxConcurrentSessions="10000"/>
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
<!--<dataContractSerializer maxItemsInObjectGraph="2147483646"/>-->
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
</configuration>

And we are trying to call the service with POSTMAN like this:

This is the raw body:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:ProcesarListaCuentasCobrarCIA100/>
   </soapenv:Body>
</soapenv:Envelope>

But, we are getting this response

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <s:Fault>
            <faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:DestinationUnreachable</faultcode>
            <faultstring xml:lang="es-CO">The message with To 'http://xx.143.46.82:8733/xxServicioDistribucion.AnalisisDatos.Servicios.CuentasCobrar/ProcesarListaCuentasCobrarCIA100/' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher.  Check that the sender and receiver's EndpointAddresses agree.</faultstring>
        </s:Fault>
    </s:Body>
</s:Envelope>

Content type heaer is text/xml.

and we are trying to use a POST

Upvotes: 23

Views: 111177

Answers (4)

smathew
smathew

Reputation: 1

From wcftestlient:

  1. Copy the XML from the XML tab to postman's body/row with type XML. Make sure to remove the headers from the body.

  2. Add soapaction to the header tab with SOAP action name.

Upvotes: 0

фымышонок
фымышонок

Reputation: 1590

  1. Run your WCF. For example https://learn.microsoft.com/en-us/dotnet/framework/wcf/getting-started-tutorial enter image description here

  2. Open wsdl and find Action enter image description here

  3. You can also find Action in WCF test client enter image description here enter image description here
  4. In PostMan URL - from wsdl - http://localhost:8000/GettingStarted/CalculatorService/

Headers -

Content-Type: text/xml

SOAPAction: http://Microsoft.ServiceModel.Samples/ICalculator/Add enter image description here 4. From WCF test Client add body. For me body is

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
  <s:Body>
    <Add xmlns="http://Microsoft.ServiceModel.Samples">
      <n1>1</n1>
      <n2>1</n2>
    </Add>
  </s:Body>
</s:Envelope>

In dropdown chose - xml enter image description here Send enter image description here

Upvotes: 41

Greg Quinn
Greg Quinn

Reputation: 2188

I found the easiest way to get WCF calls working in Postman is as follows...

1.) Open Fiddler and debug your WCF project locally, the Visual Studio WCF Test Client opens.

2.) In the WCF Test Client invoke a call to your service method to get a response.

3.) Click on the request in Fiddler.

4.) Click on the 'RAW' tab in fiddler to see the request, and copy the envelope tag in the request header.

It should look something like

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><YourMethodName xmlns="http://yourserver.com/serviceName/v1.0"/></s:Body></s:Envelope>

5.) Create a new request in Postman, and open the BODY tab, select the 'raw' radio button.

6.) Set content type drop down to 'XML'.

7.) Paste the envelope tag from above into the BODY field in Postman.

8.) Set the URL in Postman to whatever the request is being made in Fiddler, it will be the first line in the request in Fiddler, something like http://server/yourservice.svc

9.) Change the request type in Postman to POST

10.) Switch to the HEADERS tab in Postman, add a CONTENT-TYPE header, with a value of 'text/html'

11.) In the Fiddler request , you will see a SOAPAction header, copy the URL in this header

12.) In the HEADERS tab in Postman, add a 'SOAPAction' header, and paste the URL header into this value.

13.) Run your service!

Bonus

If you want to call a remote WCF service from Postman (that you can't run locally), debug your local project, so the WCF Test Client opens.

1.) Right-click on the 'My Service Projects' tree node in WCF Test Client, and click 'Add Service'.

2.) Enter your service URL

3.) Invoke a method on it as you would have done a local service, then track in Fiddler and add to Postman as per the steps above.

Upvotes: 6

Walter
Walter

Reputation: 528

IIRC when you make SOAP calls to a WCF server, there are HTTP headers that have to be set in addition to the body content.

My old SOAP calls have headers of the form:

SOAPAction: http://domain/EndPoint

You may need to check this. If you have a working client, capture the traffic with Fiddler. Also, I have the content-type set to "text/xml; charset=utf-8" and I seem to recall that some servers are picky about the content-type on POST.

Upvotes: 13

Related Questions