Trouble Consuming Java Web Service with .NET Clien

2019-09-15 01:50发布

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.

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

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

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.

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?

BTW, the webservice is a black box, no coding changes can occur there.

Thanks.

2条回答
Juvenile、少年°
2楼-- · 2019-09-15 02:26

Try changing your binding configuration to the following:

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

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.

See MTOM for a detailed description of this encoding type.

查看更多
Evening l夕情丶
3楼-- · 2019-09-15 02:30

Please leave out the Security stuff

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

from your binding. Because your messages will be protected according to the setting, and since JBOSS dispatcher model is different from WCF dispatcher, so it could not decrypt your messages.

查看更多
登录 后发表回答