2013-03-01 2 views
0

Как указано в заголовке, у меня есть служба WCF, размещенная в службе Windows. Когда я использую Visual Studio WCFTestClient, метод GetVersion() (который просто возвращает строку) отлично работает. Когда я пытаюсь вызвать тот же метод с Java-клиента, я получаю недопустимую ошибку имени хоста.Windows Hosted WCF Service Возвращает 400 Bad Request Недопустимое имя хоста для клиента JAVA

Использование Wireshark Я отслеживал XML сообщений и получил следующее:

------- Переданные ---------

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> 

------ Ответ ------------

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> 


Я играл с параметром хоста, используя S полное DNS-имя erver, но результат был таким же. Это конфигурационный файл:

----- 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> 

Я использую NetBeans для клиента Java и код прямо вперед:

- ----- Код 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(); 

Любые указатели/отладочные трюки помогут. Я не знаком с Java, поэтому я не уверен, с чего начать, но, похоже, что-то в отправляемом сообщении неверно, и я могу изменить сообщение или конфигурацию службы, чтобы знать, чего ожидать, Я просто не знаю, что это такое.

Заранее благодарен!

+0

Кажется, проблема с сетью не WCF. Вы используете java-код с другого компьютера? Проверьте настройки сети и IIS. –

ответ

3

вопрос был на самом деле в 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(); 

должно быть на самом деле

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(); 

Какая разница 3 буквы сделать!

Спасибо за помощь NileshKRathod.

0

Попробуйте для кода модели сервиса, он может помочь вам ...

<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> 

Я надеюсь, что это поможет. :)