2012-06-18 65 views
0

WCF新手在這裏,我試圖讓.NET 4.0客戶端使用JBOSS中託管的Web服務。我相信Web服務的結果正在使用x-fire進行序列化。客戶端使用WCF連接到服務。這在使用Ntlm來驗證呼叫者的內部Web服務中。使用.NET客戶端時遇到麻煩消費Java Web服務

我可以將服務引用添加到我的客戶端,並調用服務器上的某個方法。我已經確定請求正在發送,並且確實回覆了。問題是響應不是傳統的SOAP格式,我相信標準的WCF綁定無法解釋這一點。下面是關於應用的一些信息:

的app.config

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="myBinding" > 
      <security mode="TransportCredentialOnly"> 
       <transport clientCredentialType="Ntlm" proxyCredentialType="None" 
        realm="" /> 
       <message clientCredentialType="UserName" algorithmSuite="Default" /> 
      </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://server/services/WS" binding="basicHttpBinding" 
      bindingConfiguration="myBinding" contract="myContract" 
      name="myEndpoint" /> 
    </client> 
    </system.serviceModel> 

請求被髮送到服務器...從服務器回來

POST http://server/services/WS HTTP/1.1 
Content-Type: text/xml; charset=utf-8 
SOAPAction: "" 
Accept-Encoding: gzip, deflate,gzip, deflate,gzip, deflate 
Authorization: NTLM 
Host: server 
Content-Length: 145 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><getAppInfo xmlns="http://ws.application.com"/></s:Body></s:Envelope> 

響應(從小提琴手拉)..

HTTP/1.1 200 OK 
Connection: close 
Date: Mon, 18 Jun 2012 19:48:04 GMT 
Server: Microsoft-IIS/6.0 
X-Powered-By: ASP.NET 
X-Powered-By: Servlet 2.5; JBoss-5.0/JBossWeb-2.1 
Set-Cookie: blah; Path=/ 
Content-Type: multipart/related; type="application/xop+xml"; start="<[email protected]>"; start-info="text/xml";  boundary="----=_Part_14_20837339.1340048884628";charset=UTF-8 


------=_Part_14_20837332219.1340048884628 
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml" 
Content-Transfer-Encoding: 8bit 
Content-ID: <[email protected]> 

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><getAppInfoResponse xmlns="http://ws.app.com"><out><apiVersion xmlns="http://dto.ws.app.com">55</apiVersion><dbBuildNumber xmlns="http://dto.ws.app.com">12312</dbBuildNumber><appBuildNumber xmlns="http://dto.ws.app.com" xsi:nil="true" /></out></getAppInfoResponse></soap:Body></soap:Envelope> 
------=_Part_14_20837332219.1340048884628-- 

以及來自.net客戶端的錯誤消息如下...

The content type multipart/related; type="application/xop+xml"; start="<[email protected]>"; start-info="text/xml";  boundary="----=_Part_14_20837332219.1340048884628";charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 738 bytes of the response were: ' 

其餘的異常只是重複從服務器的初始響應。

我的猜測是我需要做一個自定義綁定,或類似的東西。我一直在尋找一個很好的例子來說明如何做到這一點,但他們似乎都留下了一些讓我無法將所有東西連接在一起的東西。如果我可以使自定義綁定工作,我的猜測是解析響應,並將所有內容傳遞給WCF解串器,因爲這是實際的soap響應。

有沒有人有任何想法如何做到這一點,遵循的好例子,或者完全不同的方法?

順便說一句,web服務是一個黑匣子,在那裏不會發生任何編碼變化。

謝謝。

回答

3

試着改變你的綁定配置以下內容:

<binding name="myBinding" messageEncoding="Mtom"> 

正如你可以看到messageEncoding設置爲MTOM應該把你的問題的關心,因爲這是JBoss服務器正在返回。

有關此編碼類型的詳細說明,請參閱MTOM

+0

謝謝,它的工作!什麼讓你知道它正在返回Mtom?它是內容類型嗎? –

+0

是的內容類型是決定性因素。 –

0

請從您綁定離開了安全的東西

<security mode="TransportCredentialOnly"> 
       <transport clientCredentialType="Ntlm" proxyCredentialType="None" 
        realm="" /> 
       <message clientCredentialType="UserName" algorithmSuite="Default" /> 
      </security> 

。因爲您的郵件將根據設置進行保護,並且由於JBOSS調度程序模型與WCF調度程序不同,所以它無法解密您的郵件。