使用.NET客户端消耗Java Web服务的麻烦

时间:2012-06-18 21:11:04

标签: .net wcf jboss wcf-binding xfire

WCF新手在这里,我试图让.NET 4.0客户端使用JBOSS中托管的Web服务。我相信来自Web服务的结果正在使用x-fire进行序列化。客户端使用WCF连接到服务。这在内部Web服务中使用Ntlm来验证调用者。

我可以向我的客户端添加服务引用,并调用服务器上的其中一个方法。我已经确定请求正在发送,并且确实会回复。问题是响应不是传统的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="<soap.xml@xfire.codehaus.org>"; 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: <soap.xml@xfire.codehaus.org>

<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="<soap.xml@xfire.codehaus.org>"; 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响应。

有没有人对如何做到这一点有任何想法,可以采用好的例子,或者可能采用不同的方法?

BTW,网络服务是一个黑盒子,那里不会发生编码变化。

感谢。

2 个答案:

答案 0 :(得分:3)

尝试将绑定配置更改为以下内容:

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

正如您所看到的,messageEncoding设置为Mtom,它应该处理您的问题,因为这是JBoss服务器返回的内容。

有关此编码类型的详细说明,请参阅MTOM

答案 1 :(得分:0)

请遗漏安全资料

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

来自你的绑定。因为您的消息将根据设置受到保护,并且由于JBOSS调度程序模型与WCF调度程序不同,因此无法解密您的消息。

相关问题