Java 客户端无法使用 WCF 服务

标签 java wcf

我有一个 WCF 网络服务,它由 WCF 客户端和 Java 使用。 .net 客户端工作正常,但 java 客户端无法通信并抛出以下错误。

<s:Fault>
  <faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none" xmlns="">a:ActionNotSupported</faultcode>
  <faultstring xml:lang="en-US" xmlns="">The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</faultstring>
</s:Fault>

我已经捕获了这两个请求,但无法找出实际问题。

这是 .net 客户端发送的请求。

<MessageLogTraceRecord>
  <HttpRequest xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
    <Method>POST</Method>
    <QueryString></QueryString>
    <WebHeaders>
      <Connection>Keep-Alive</Connection>
      <Content-Length>277</Content-Length>
      <Content-Type>text/xml; charset=utf-8</Content-Type>
      <Expect>100-continue</Expect>
      <Host>devint</Host>
      <VsDebuggerCausalityData>uIDPoz4EUGTdY91Co1FESc2IENsAAAAAfpHU4m1Iok+wSxmrwkiWZ9iNzD51RjZMnpnEBbceBDcACQAA</VsDebuggerCausalityData>
      <SOAPAction>"http://tempuri.org/Test/IsPilotUser"</SOAPAction>
      <X-Forwarded-For>xx.xxx.xxx.xxx</X-Forwarded-For>
      <X-Optier-Context-Address>43143760</X-Optier-Context-Address>
    </WebHeaders>
  </HttpRequest>
  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
      <To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://service url here</To>
      <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/Test/IsPilotUser</Action>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <IsPilotUser xmlns="http://tempuri.org/">
        <UserID>AA</UserID>
      </IsPilotUser>
    </s:Body>
  </s:Envelope>
</MessageLogTraceRecord>

下面是java客户端生成的请求-

<MessageLogTraceRecord>
  <HttpRequest xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
    <Method>POST</Method>
    <QueryString></QueryString>
    <WebHeaders>
      <Cache-Control>no-cache</Cache-Control>
      <Connection>keep-alive</Connection>
      <Pragma>no-cache</Pragma>
      <Content-Length>1414</Content-Length>
      <Content-Type>text/xml; charset=utf-8</Content-Type>
      <Accept>text/xml, text/html, image/gif, image/jpeg, *; q=.2, * / *; q=.2</Accept>
      <Host>devint</Host>
      <User-Agent>Java/1.6.0_25</User-Agent>
      <SOAPAction>""</SOAPAction>
      <X-Optier-Context-Address>43526520</X-Optier-Context-Address>
    </WebHeaders>
  </HttpRequest>
  <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header xmlns:hdr="http://xml.example.com/ns/appmw/soap/1.0/header">
      <hdr:RequestID xmlns:hdr="http://xml.example.com/ns/appmw/soap/1.0/header">287933.1372254929205.341301</hdr:RequestID>
      <hdr:Timestamp xmlns:hdr="http://xml.example.com/ns/appmw/soap/1.0/header">1372254929205</hdr:Timestamp>
      <hdr:Principal xmlns:hdr="http://xml.example.com/ns/appmw/soap/1.0/header">
        <saml:Assertion xmlns:saml="http://xml.example.com/ns/appmw/soap/1.0/saml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Issuer="PingFederate SiteMinder SOAP Connector" xsi:type="saml:AuthenticationAssertionType">
          <saml:Subject>
            <saml:NameIdentifier>
              <saml:SecurityDomain>KerberosID</saml:SecurityDomain>
              <saml:Name>None</saml:Name>
            </saml:NameIdentifier>
            <saml:SubjectConfirmation>
              <saml:AuthenticationMethod>Netegrity</saml:AuthenticationMethod>
              <saml:SubjectConfirmationData>None</saml:SubjectConfirmationData>
            </saml:SubjectConfirmation>
          </saml:Subject>
        </saml:Assertion>
      </hdr:Principal>
      <To SOAP-ENV:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://service url here</To>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
      <pf:AttributesRequest xmlns:pf="http://xml.ms.com/ns/webinfra/pingfederate/sso-attributes">
        <pf:Data>
          <pf:HumanNo></pf:HumanNo>
          <pf:Originator>None</pf:Originator>
          <pf:UniqueID>None</pf:UniqueID>
        </pf:Data>
        <pf:Attribute>
          <pf:Name>IsPilotUserResult</pf:Name>
        </pf:Attribute>
      </pf:AttributesRequest>
    </SOAP-ENV:Body>
  </SOAP-ENV:Envelope>
</MessageLogTraceRecord>

我不熟悉 Java,因此不胜感激。

最佳答案

您的 java 客户端发送此 http header :

SOAPAction=""

当 .Net 发送这个时:

SOAPAction="http://tempuri.org/Test/IsPilotUser"

强制 java 客户端发送正确的值。

关于Java 客户端无法使用 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17325234/

相关文章:

multithreading - .NET 4.5 增加 WCF 客户端调用异步?

c# - 为什么我的 WCF channel 失败?

java - Eclipse RCP 应用程序 - 创建首选项页面条目,该条目已加密保存

java - 如何在 Spring MVC 中向拦截器注入(inject)属性

java - SCJP 需要适当的指导

java - Jasper 报告找不到包 net.sf.jasperreports.engine

c# - 无法以与 C# 相同的格式为 WCF 服务传递 java 参数

java - 将 facebook 连接个人资料图片保存到自己的服务器

java - 启动Android需要一些指导

c# - WCF - 回调接口(interface)可以指定为通用接口(interface)吗?