由於標題指示我有一個Windows服務託管的WCF服務。當我使用Visual Studio WCFTestClient時,它的GetVersion()方法(它只是返回一個字符串)工作正常。當我嘗試從Java客戶端調用相同的方法時,我得到一個無效的主機名錯誤。Windows託管的WCF服務返回400錯誤的請求無效的主機名到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 erver的完整DNS名稱,但結果相同。這是配置文件:
-----配置------
<?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>
我使用Java客戶端NetBeans和代碼是直截了當:
- ----- 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並不熟悉,所以我不確定從哪裏開始,但似乎發送的消息中有些內容是錯誤的,我可以更改消息或服務的配置以知道期望的內容,我只是不知道那是什麼。
在此先感謝!
似乎是網絡問題而不是WCF。你是從不同的機器運行java代碼嗎?檢查網絡和IIS設置。 – 2013-03-01 22:28:14