.NET客户端无法正常使用Java Web Service [英] Trouble Consuming Java Web Service with .NET Client
问题描述
这里是WCF新手,我正在尝试让.NET 4.0客户端使用JBOSS中托管的Web服务.我相信Web服务的结果正在使用x-fire进行序列化.客户端使用WCF连接到服务.这是使用Ntlm对调用方进行身份验证的内部Web服务中的内容.
WCF newbie here, I am attempting to make a .NET 4.0 client consume a web service hosted in JBOSS. I believe the results from the web service are being serialized using x-fire. The client side is using WCF to connect to the service. This in an internal web service that uses Ntlm to authenticate the caller.
我能够向我的客户端添加服务引用,并调用服务器上的方法之一.我确定正在发送请求,并且确实返回了响应.问题在于响应不是采用传统的SOAP格式,我相信标准的WCF绑定无法解释这一点.以下是有关该应用的一些信息:
I am able to add a service reference to my client, and call one of the methods on the server. I have determined that the request is being sent, and a response is indeed coming back. The problem is that the response is not in the traditional SOAP format, and I believe the standard WCF bindings are unable to interpret this. Here's some information on the app:
app.config
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>
正在将请求发送到服务器...
Request being sent to the server...
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>
从服务器返回的响应(从提琴手那里提取)...
Response coming back from the server (pulled from fiddler)...
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客户端的错误消息如下...
and the error message from the .net client is as follows...
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: '
其余的异常只会重复服务器的初始响应.
the rest of the exception just repeats the initial response from the server.
我的猜测是我需要进行自定义绑定或类似的操作.我到处找了一个很好的例子来说明如何执行此操作,但是它们似乎都遗漏了一些东西,使我无法将所有内容连接在一起.如果我可以使自定义绑定正常工作,我的猜测是解析响应,并将------行之间的所有内容都传递给WCF解串器,因为这是实际的肥皂响应.
My guess is that I need to make a custom binding, or something like that. I've looked around for a good example on how to do this, but they all seem to leave something out that prevents me from connecting everything together. If I could get the custom binding working, my guess would be to parse the response, and pass everything in between the ------ lines to the WCF deserializer, since this is the actual soap response.
有人对如何执行此操作有任何想法,可以遵循的良好示例或完全不同的方法吗?
Does anyone have any ideas on how to do this, good examples to follow, or perhaps a different approach altogether?
顺便说一句,Web服务是一个黑匣子,在此处无法进行任何编码更改.
BTW, the webservice is a black box, no coding changes can occur there.
谢谢.
推荐答案
尝试将绑定配置更改为以下内容:
Try changing your binding configuration to the following:
<binding name="myBinding" messageEncoding="Mtom">
您可以看到messageEncoding设置为Mtom,这应该解决您的问题,因为这是JBoss服务器返回的内容.
As you can see the messageEncoding is set to Mtom which should take care of your issue since that is what the JBoss server is returning.
有关此编码类型的详细说明,请参见 MTOM .
See MTOM for a detailed description of this encoding type.
这篇关于.NET客户端无法正常使用Java Web Service的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!