javawcfwcf-clienthostnamewcf-configuration

Windows Hosted WCF Service Returns 400 Bad Request Invalid Hostname To JAVA Client


As the title indicates I have a WCF Service hosted in a Windows service. When I use the Visual Studio WCFTestClient it the GetVersion() Method (which just returns a string) works fine. When I attempt to call the same method from a Java client I get an invalid hostname error.

Using Wireshark I tracked the XML messages and got the following:

-------Sent---------

POST /CommunicatorService.svc HTTP/1.1
Accept: text/xml, multipart/related
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/ICommunicatorService/GetVersion"

User-Agent: JAX-WS RI 2.2.4-b01
Host: 192.168.201.210:7770
Connection: keep-alive
Content-Length: 373

<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><GetVersion xmlns="http://tempuri.org/" xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:ns3="http://schemas.datacontract.org/2004/07/DieboldEras.WorkflowContracts" xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/"/></S:Body></S:Envelope>

------Response------------

HTTP/1.1 400 Bad Request
Content-Type: text/html
Date: Fri, 01 Mar 2013 20:51:18 GMT

Connection: close
Content-Length: 39

<h1>Bad Request (Invalid Hostname)</h1>


I have played around with the Host parameter, using the Server's full DNS name but the result was the same. This is the config file:

-----Config------

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="DieboldEras.ImagewayCommunicator.Components.CommunicatorService" behaviorConfiguration="DieboldEras.ImagewayCommunicator.Components.CommunicatorServiceBehavior">
        <endpoint binding="basicHttpBinding"
            bindingConfiguration="basicHttpBinding" name="basicHttp" bindingName="basicHttpBinding"
            contract="DieboldEras.ImagewayCommunicator.Components.ICommunicatorService" >
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://192.168.201.210:7770/CommunicatorService" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="DieboldEras.ImagewayCommunicator.Components.CommunicatorServiceBehavior">
          <!-- 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="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHTTPBinding"/>
      </wsHttpBinding>
      <mexHttpBinding>
        <binding name="mexHTTPBinding"/>
      </mexHttpBinding>
      <basicHttpBinding>
    <binding name="basicHttpBinding" />
      </basicHttpBinding>
    </bindings>
    <client />
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

I'm using NetBeans for the Java Client and the code is straight forward:

------Java Code--------

CommunicatorService service = new CommunicatorService();
ICommunicatorService port = service.getBasicHttp();
((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://192.168.201.210:7770/CommunicatorService.svc");
String version = port.getVersion();

Any pointers/debugging tricks would help. I'm not that familiar with Java so I'm not sure where to start, but it would seem something in the message being sent is wrong, and either I can change the message or the config of the service to know what to expect, I just don't know what that thing is.

Thanks in advance!


Solution

  • The issue was actually in the Java Code:

    CommunicatorService service = new CommunicatorService();
    ICommunicatorService port = service.getBasicHttp();
    ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://192.168.201.210:7770/CommunicatorService.svc");
    String version = port.getVersion();
    

    should actually be

    CommunicatorService service = new CommunicatorService();
    ICommunicatorService port = service.getBasicHttp();
    ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://192.168.201.210:7770/CommunicatorService");
    String version = port.getVersion();
    

    What a difference 3 letters make!

    Thanks for the help NileshKRathod.