Huzaifa Tapal
Huzaifa Tapal

Reputation: 191

.NET 4 WCF SOAP Service Http POST returns 404 NOT Found

I have WCF hosted SOAP service which I'm able to hit from the browser as well as from my SOAP client fine when making HTTP GET requests, however, when doing any HTTP POST requests, the response is a 404 Not Found.

My Web.config looks like:

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
    <bindings>
        <wsHttpBinding>
            <binding>
                <security mode="Transport">
                    <transport clientCredentialType="Certificate" />
                </security>
                <readerQuotas maxDepth="15" maxStringContentLength="524288" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>
        </wsHttpBinding>
        <basicHttpBinding>
            <binding>
                <readerQuotas maxDepth="15" maxStringContentLength="524288" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>
        </basicHttpBinding>
    </bindings>
</system.serviceModel>

My service is defined in the markup using the .svc file as:

<%@ ServiceHost Language="C#" Debug="true" Service="Boca.WebServices.Billing.QBService" CodeBehind="QBService.svc.cs" %>

Again, I can hit my service using the browser and a SOAP client as follows using an HTTP GET but not with HTTP POST:

What am I doing wrong? Should I not be using the .svc markup and just define my service in the Web.config?

UPDATE:

When I "start debug" my WCF project from within VS 2010 using IIS Express on a localhost:8181 port, the HTTP POSTS to the service work. It's only when the service is hosted through IIS the HTTP POST to the service are being rejected or not found.

Upvotes: 8

Views: 16233

Answers (2)

Huzaifa Tapal
Huzaifa Tapal

Reputation: 191

I've solved the problem. It, after all, was not an IIS issue rather an issue with the me not configuring the <basicHttpBinding> with <security> node. I din't thoroughly read about bindings and how they work, so I thought that adding the <wsHttpBinding> alongside the <basicHttpBinding> would add SSL support for WCF.

Doing so and configuring the default <wsHttpBinding> with the <security> node definitely allowed me to GET the SOAP metadata securely even though internally it was still using the <basicHttpBinding>, however POSTs were not supported.

I updated my configuration so that the transport clientCredentialType was set to None and that resolved the issue:

<bindings>
    <basicHttpBinding>
        <binding name="QBService_BasicHttpBinding">
            <security mode="Transport">
                <transport clientCredentialType="None" />
            </security>
            <readerQuotas maxDepth="15" maxStringContentLength="524288" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binding>
    </basicHttpBinding>
</bindings>

Upvotes: 10

Richard Blewett
Richard Blewett

Reputation: 6109

Assuming you are using .NET 4 your service will be listening on one or more endpoints using basicHttpBinding - this is the default if you don't specify an endpoint when using HTTP

If you have only one service contract then your service will listen for HTTP POST at the address ending with .svc. If you have more than one service contract then it hosts each contract at an address like <path to .svc>/<serviceContractname>

The service is expecting a SOAP request so you will need to POST an XML document that matches SOAP 1.1 (basicHttpBinding defaults to this). The easiest way to achieve this is to build a proxy using Add Service Reference in a client project and make calls through the generated proxy class - the WCF plumbing will generate the appropriate message and POST it to the service

Upvotes: 2

Related Questions