WCF与java的互操作性:EndpointNotFoundException

时间:2014-09-01 08:48:33

标签: c# web-services wcf interop

我要编写一个必须传递用java编写的给定测试的Web服务。它有一个具体的规范:

.-必须使用SSL保护Web服务。

.-将使用Web服务安全性UsernameToken Profile 1.0 OASIS Standard 200401,2004年3月进行身份验证。使用wsse类型的凭据:PasswordText。

我无法访问客户端代码,只能访问测试Web服务所有必要操作的java程序。

我是WCF的新手。首先,我使用svcutil和规范中包含的WSDL文件创建了一个代理类:

namespace SEPEWS
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace = "http://impl.ws.application.proveedorcentro.meyss.spee.es", ConfigurationName = "IProveedorCentroEndPoint")]
public interface IProveedorCentroEndPoint
{

    [System.ServiceModel.OperationContractAttribute(Action = "crearCentro", ReplyAction = "http://Microsoft.WCF.Documentation/ResponseToOCAMethod")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    crearCentroOutput crearCentro(crearCentroInput request);

    [System.ServiceModel.OperationContractAttribute(Action = "obtenerDatosCentro", ReplyAction = "http://Microsoft.WCF.Documentation/ResponseToOCAMethod")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    obtenerDatosCentroOutput obtenerDatosCentro(obtenerDatosCentroInput request);

    [System.ServiceModel.OperationContractAttribute(Action = "crearAccion", ReplyAction = "http://Microsoft.WCF.Documentation/ResponseToOCAMethod")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    crearAccionOutput crearAccion(crearAccionInput request);

    [System.ServiceModel.OperationContractAttribute(Action = "obtenerAccion", ReplyAction = "http://Microsoft.WCF.Documentation/ResponseToOCAMethod")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    obtenerAccionOutput obtenerAccion(obtenerAccionInput request);

    [System.ServiceModel.OperationContractAttribute(Action = "obtenerListaAcciones", ReplyAction = "http://Microsoft.WCF.Documentation/ResponseToOCAMethod")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    obtenerListaAccionesOutput obtenerListaAcciones(obtenerListaAccionesInput request);

    [System.ServiceModel.OperationContractAttribute(Action = "eliminarAccion", ReplyAction = "http://Microsoft.WCF.Documentation/ResponseToOCAMethod")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    eliminarAccionOutput eliminarAccion(eliminarAccionInput request);

}

这是web.config:

<?xml version="1.0"?>
<configuration>
  <appSettings>        
      <add key="CustomIISServiceHostEndPoint" value="https://localhost/virtualtutor/CaeWebServices/SEPEWS/SEPEWS.svc"/>
  </appSettings>
  <connectionStrings/>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <authentication mode="Windows"/>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
  </system.web>
  <system.webServer>
    <directoryBrowse enabled="true"/>
  </system.webServer>

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information,ActivityTracing"
        propagateActivity="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="d:\ftpin\sepe\messages.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="xml" />
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>
  <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true" logMalformedMessages="true"
        logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
        maxMessagesToLog="3000" maxSizeOfMessageToLog="20000" />
      <endToEndTracing propagateActivity="true" activityTracing="true"
        messageFlowTracing="true" />
    </diagnostics>
    <bindings>
      <customBinding>
        <binding name="DefaultBinding" >
          <transactionFlow />
          <security authenticationMode="SecureConversation" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" securityHeaderLayout="Lax" requireDerivedKeys="false">
            <secureConversationBootstrap authenticationMode="UserNameForSslNegotiated" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />
          </security>
          <customTextMessageEncoding encoding="utf-8" mediaType="text/xml" messageVersion="Soap11WSAddressing10" />
          <httpsTransport />
        </binding>
      </customBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="SEPEWS.SEPEWSBehavior" name="SEPEWS.SEPEWS">
        <endpoint address="https://localhost/virtualtutor/CaeWebServices/SEPEWS/SEPEWS.svc" binding="customBinding" bindingConfiguration="DefaultBinding" contract="IProveedorCentroEndPoint" >
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SEPEWS.SEPEWSBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceCredentials>
            <serviceCertificate findValue="localhost"
                                storeLocation="LocalMachine"
                                storeName="My"
                                x509FindType="FindBySubjectName" />
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SEPEWS.CustomUsernameValidator, SEPEWS" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <extensions>
      <bindingElementExtensions>
        <add name="customTextMessageEncoding"
             type="SEPEWS.CustomTextMessageEncodingElement, SEPEWS"/>
      </bindingElementExtensions>
    </extensions>
  </system.serviceModel>
</configuration>

当我运行客户端测试时,这是我收到的第一条消息(来自WCF诊断跟踪):

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>262163</EventID>
<Type>3</Type>
<SubType Name="Information">0</SubType>
<Level>8</Level>
<TimeCreated SystemTime="2014-09-01T07:37:23.4007917Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{f81337a5-add3-4e76-9866-f5a9f9b076b2}" />
<Execution ProcessName="w3wp" ProcessID="3420" ThreadID="58" />
<Channel />
<Computer>JCSEGUI-PC</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information">
<TraceIdentifier>http://msdn.microsoft.com/es-ES/library/System.ServiceModel.Channels.MessageReceived.aspx</TraceIdentifier>
<Description>Se recibió un mensaje a través de un canal.</Description>
<AppDomain>/LM/W3SVC/1/ROOT/virtualtutor/CaeWebServices/SEPEWS-12-130540306415826877</AppDomain>
<Source>System.ServiceModel.Activation.HostedHttpContext+HostedHttpInput/27502329</Source>
<ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/MessageTransmitTraceRecord">
<MessageProperties>
<AllowOutputBatching>False</AllowOutputBatching>
<Via>https://jcsegui-pc/virtualtutor/CaeWebServices/SEPEWS/SEPEWS.svc</Via>
</MessageProperties>
<MessageHeaders>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<wsse:UsernameToken wsu:Id="UsernameToken-1">
<wsse:Username>
<!-- Removed-->
</wsse:Username>
<wsse:Password>
<!-- Removed-->
</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<wsa:To xmlns:wsa="http://www.w3.org/2005/08/addressing">https://localhost/virtualtutor/CaeWebServices/SEPEWS/SEPEWS.svc</wsa:To>
<wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing">urn:uuid:e86a5e30-a3aa-4692-be17-2e044d0fcf1f</wsa:MessageID>
<wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">obtenerDatosCentro</wsa:Action>
</MessageHeaders>
</ExtendedData>
</TraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
</E2ETraceEvent>

在该消息之后,该服务抛出以下异常:

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>131075</EventID>
<Type>3</Type>
<SubType Name="Error">0</SubType>
<Level>2</Level>
<TimeCreated SystemTime="2014-09-01T07:37:23.4007917Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{f81337a5-add3-4e76-9866-f5a9f9b076b2}" />
<Execution ProcessName="w3wp" ProcessID="3420" ThreadID="58" />
<Channel />
<Computer>JCSEGUI-PC</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error">
<TraceIdentifier>http://msdn.microsoft.com/es-ES/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier>
<Description>Se está iniciando una excepción.</Description>
<AppDomain>/LM/W3SVC/1/ROOT/virtualtutor/CaeWebServices/SEPEWS-12-130540306415826877</AppDomain>
<Exception>
<ExceptionType>System.ServiceModel.EndpointNotFoundException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>There was no channel that could accept the message with action 'obtenerDatosCentro'.</Message>
<StackTrace>
en System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(Exception e, Message message)
en System.ServiceModel.Channels.DatagramChannelDemuxer`2.ProcessItem(TInnerItem item)
en System.ServiceModel.Channels.DatagramChannelDemuxer`2.HandleReceiveResult(IAsyncResult result)
en System.ServiceModel.Channels.DatagramChannelDemuxer`2.OnReceiveComplete(IAsyncResult result)
en System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
en System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
en System.ServiceModel.Channels.ReplyChannel.HelpReceiveRequestAsyncResult.OnReceiveRequest(IAsyncResult result)
en System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
en System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
en System.Runtime.InputQueue`1.AsyncQueueReader.Set(Item item)
en System.Runtime.InputQueue`1.EnqueueAndDispatch(Item item, Boolean canDispatchOnThisThread)
en System.Runtime.InputQueue`1.EnqueueAndDispatch(T item, Action dequeuedCallback, Boolean canDispatchOnThisThread)
en System.ServiceModel.Channels.SingletonChannelAcceptor`3.Enqueue(QueueItemType item, Action dequeuedCallback, Boolean canDispatchOnThisThread)
en System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.CompleteParseAndEnqueue(IAsyncResult result)
en System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.HandleParseIncomingMessage(IAsyncResult result)
en System.Runtime.AsyncResult.SyncContinue(IAsyncResult result)
en System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor replyChannelAcceptor, Action dequeuedCallback, AsyncCallback callback, Object state)
en System.ServiceModel.Channels.HttpChannelListener`1.HttpContextReceivedAsyncResult`1.ProcessHttpContextAsync()
en System.ServiceModel.Channels.HttpChannelListener`1.BeginHttpContextReceived(HttpRequestContext context, Action acceptorCallback, AsyncCallback callback, Object state)
en System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
en System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
en System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
en System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
en System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
en System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
en System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace>
<ExceptionString>System.ServiceModel.EndpointNotFoundException: There was no channel that could accept the message with action 'obtenerDatosCentro'.</ExceptionString>
</Exception>
</TraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
</E2ETraceEvent>

我花了两周时间研究这个问题的可能原因和解决方案,但没有运气。我不知道该做什么/尝试使服务工作。

有任何想法/建议吗?

更新2014/09/04

将安全配置更改为此配置后:

<security authenticationMode="UserNameForSslNegotiated" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" securityHeaderLayout="Lax" requireDerivedKeys="false">

现在customUsernameAuthentication工作正常,但是当用户名和密码正确时,我得到以下异常:

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>131075</EventID>
<Type>3</Type>
<SubType Name="Error">0</SubType>
<Level>2</Level>
<TimeCreated SystemTime="2014-09-04T07:59:50.2765402Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{547695d0-f8d6-4cfe-860e-00ffcbd1fc54}" />
<Execution ProcessName="w3wp" ProcessID="1028" ThreadID="51" />
<Channel />
<Computer>JCSEGUI-PC</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error">
<TraceIdentifier>http://msdn.microsoft.com/es-ES/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier>
<Description>Starting new exception.</Description>
<AppDomain>/LM/W3SVC/1/ROOT/virtualtutor/CaeWebServices/SEPEWS-6-130542911898955184</AppDomain>
<Exception>
<ExceptionType>System.ServiceModel.Security.MessageSecurityException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The security token 'System.IdentityModel.Tokens.UserNameSecurityToken' with the 'Basic' attachment mode must be signed.</Message>
<StackTrace>
en System.ServiceModel.Security.ReceiveSecurityHeaderElementManager.EnsureAllRequiredSecurityHeaderTargetsWereProtected()
en System.ServiceModel.Security.ReceiveSecurityHeader.Process(TimeSpan timeout, ChannelBinding channelBinding, ExtendedProtectionPolicy extendedProtectionPolicy)
en System.ServiceModel.Security.MessageSecurityProtocol.ProcessSecurityHeader(ReceiveSecurityHeader securityHeader, Message&amp; message, SecurityToken requiredSigningToken, TimeSpan timeout, SecurityProtocolCorrelationState[] correlationStates)
en System.ServiceModel.Security.SymmetricSecurityProtocol.VerifyIncomingMessageCore(Message&amp; message, String actor, TimeSpan timeout, SecurityProtocolCorrelationState[] correlationStates)
en System.ServiceModel.Security.MessageSecurityProtocol.VerifyIncomingMessage(Message&amp; message, TimeSpan timeout, SecurityProtocolCorrelationState[] correlationStates)
en System.ServiceModel.Channels.SecurityChannelListener`1.ServerSecurityChannel`1.VerifyIncomingMessage(Message&amp; message, TimeSpan timeout, SecurityProtocolCorrelationState[] correlationState)
en System.ServiceModel.Channels.SecurityChannelListener`1.SecurityReplyChannel.ProcessReceivedRequest(RequestContext requestContext, TimeSpan timeout)
en System.ServiceModel.Channels.SecurityChannelListener`1.ReceiveItemAndVerifySecurityAsyncResult`2.OnInnerReceiveDone()
en System.ServiceModel.Channels.SecurityChannelListener`1.ReceiveItemAndVerifySecurityAsyncResult`2.InnerTryReceiveCompletedCallback(IAsyncResult result)
en System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
en System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
en System.Runtime.InputQueue`1.AsyncQueueReader.Set(Item item)
en System.Runtime.InputQueue`1.Dispatch()
en System.Runtime.ActionItem.DefaultActionItem.TraceAndInvoke()
en System.Runtime.ActionItem.CallbackHelper.InvokeWithoutContext(Object state)
en System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
en System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
en System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace>
<ExceptionString>System.ServiceModel.Security.MessageSecurityException: The security token 'System.IdentityModel.Tokens.UserNameSecurityToken' with the 'Basic' attachment mode must be signed.</ExceptionString>
</Exception>
</TraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
</E2ETraceEvent>

我不知道下一步该尝试什么......

更新II 2014/09/04

解决!!!

将authenticationMode更改为UserNameOverTransport它可以正常工作。

所以最终的安全标签将是:

<security authenticationMode="UserNameOverTransport" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" securityHeaderLayout="Lax">

无论如何,谢谢你

0 个答案:

没有答案