简体   繁体   English

Windows托管的WCF服务向JAVA客户端返回400错误的请求无效的主机名

[英]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. 如标题所示,我在Windows服务中托管了WCF服务。 When I use the Visual Studio WCFTestClient it the GetVersion() Method (which just returns a string) works fine. 当我使用Visual Studio WCFTestClient时,GetVersion()方法(仅返回一个字符串)可以正常工作。 When I attempt to call the same method from a Java client I get an invalid hostname error. 当我尝试从Java客户端调用相同的方法时,收到无效的主机名错误。

Using Wireshark I tracked the XML messages and got the following: 使用Wireshark,我跟踪了XML消息并获得了以下信息:

-------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. 我使用服务器的完整DNS名称来处理Host参数,但结果是相同的。 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: 我将NetBeans用于Java客户端,代码很简单:

------Java Code-------- ------ Java代码--------

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. 我对Java不太熟悉,所以我不确定从哪里开始,但是似乎在发送的消息中出现了错误,可以更改消息或服务的配置以了解期望的内容,我只是不知道那是什么东西。

Thanks in advance! 提前致谢!

The issue was actually in the Java Code: 问题实际上出在Java代码中:

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! 3个字母有什么不同!

Thanks for the help NileshKRathod. 感谢NileshKRathod的帮助。

Try this for your service model code, it may help you... 为您的服务模型代码尝试此操作,可能会帮助您...

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
  <service name="VInfotech.Server.Intranet.IntranetService" behaviorConfiguration="IntranetService.Service1Behavior">
    <!-- Service Endpoints -->
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="VInfotech.Server.Intranet.IIntranet">
      <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
  </service>
  <service name="VInfotech.Server.Intranet.MobileServicesController" behaviorConfiguration="ServBehave">
    <endpoint address="RestService" bindingConfiguration="StreamedRequestWebBinding" binding="webHttpBinding" behaviorConfiguration="restPoxBehavior" contract="VInfotech.Server.Intranet.IMobileServices" />
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="StreamedRequestWebBinding"
    bypassProxyOnLocal="true"
             useDefaultWebProxy="false"
             hostNameComparisonMode="WeakWildcard"
             sendTimeout="10:15:00"
             openTimeout="10:15:00"
             receiveTimeout="10:15:00"
             maxReceivedMessageSize="9223372036854775807"
             maxBufferPoolSize="9223372036854775807"
             maxBufferSize="2147483647"
             transferMode="StreamedRequest" >
      <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
    </binding>
  </webHttpBinding>
  <basicHttpBinding>
    <binding name="Binding1" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1073741824" maxBufferPoolSize="1073741824" maxReceivedMessageSize="1073741824" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="1073741824" maxStringContentLength="1073741824" maxArrayLength="1073741824" maxBytesPerRead="1073741824" maxNameTableCharCount="1073741824"/>
    </binding>
    <!-- For Cyber Source bindings-->
    <binding name="ITransactionProcessor" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1073741824" maxBufferPoolSize="1073741824" maxReceivedMessageSize="1073741824" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="1073741824" maxStringContentLength="1073741824" maxArrayLength="1073741824" maxBytesPerRead="1073741824" maxNameTableCharCount="1073741824"/>
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="UserName" algorithmSuite="Default"/>
      </security>
    </binding>
  </basicHttpBinding>
  <!--Cyber Source bindings ends here-->
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="IntranetService.Service1Behavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
    <behavior name="ServBehave">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <!--Behavior for the REST endpoint for Help enability-->
    <behavior name="restPoxBehavior">
      <webHttp helpEnabled="true" />
    </behavior>
    <behavior name="jsonBehavior">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>
</behaviors>
<client>
  <endpoint address="https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor" binding="basicHttpBinding" bindingConfiguration="ITransactionProcessor" contract="ITransactionProcessor" name="portXML"/>
</client>
<diagnostics>
  <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" maxSizeOfMessageToLog="2000"/>
</diagnostics>

I hope this will help you. 我希望这能帮到您。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误的请求-来自Android仿真器的SOAP WCF Web服务的无效主机名异常 - Bad Request - Invalid Hostname exception for SOAP WCF Web Service from Android emulator 400错误的请求无效的主机名仅在Android应用程序中 - 400 bad request invalid hostname only in android application 用于获取访问令牌的Google oauth java客户端失败,并显示“400 Bad Request {”error“:”invalid_request“}” - Google oauth java client to get an access token fails with “400 Bad Request { ”error“ : ”invalid_request“ }” 用于获取访问令牌的Google oauth java客户端失败,并显示“400 Bad Request {”error“:”invalid_request“}” - Google oauth java client to get an access token fails with “400 Bad Request { ”error“ : ”invalid_request“ }” 带有 Java 客户端的 OData 错误请求 400 - OData Bad Request 400 with Java Client 获得 400 - 错误请求 Java 客户端 - Getting 400 - Bad Request Java Client Java服务400错误的请求错误 - java service 400 bad request error com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request Invalid Grant java Console Application - com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request Invalid Grant java Console Application Java Put-Request返回400错误请求 - Java Put-Request returns 400 Bad Request Spring MVC RestFul服务+ Jersey Client 400错误请求 - Spring MVC RestFul service + Jersey Client 400 Bad Request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM