2

请原谅我缺乏 WCF 经验,但我遇到了一个问题,我很难理解。

我工作的公司的另一个组织创建了一个 Web 服务供我使用。我相信我已经使用他们提供的 WSDL 正确地为我的项目添加了服务引用。他们的 Web 服务基于我知之甚少的 Oracle API,我不是 Oracle 开发人员。

这是我用来使用服务参考的代码:

BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
basicHttpBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

EndpointAddress epa = new EndpointAddress("https://MYENDPOINT.URL");
MyServiceReference.SERVICENAME_PortTypeClient port = new MyServiceReference.SERVICENAME_PortTypeClient(basicHttpBinding, epa);
port.ClientCredentials.UserName.UserName = SERVICE_U;
port.ClientCredentials.UserName.Password = SERVICE_P;

SOAHeader header = new SOAHeader();
header.Responsibility = SERVICE_RESPONSIBILITY;

InputParameters2 ip2 = new InputParameters2();
ip2.param1 = "abcd";
ip2.param2 = "1234"

OutputParameters2 output = port.WEB_SERVICE_FUNCTION(header, ip2);

这是我的 Web.Config 文件中有关绑定信息的信息:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="SERVICENAME_Binding">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="https://MYENDPOINT.URL"
                 binding="basicHttpBinding" bindingConfiguration="SERVICENAME_Binding"
                 contract="MyServiceReference.SERVICENAME_PortType"
                 name=SERVICENAME_Port" />
    </client>
</system.serviceModel>

当调用该服务时,我收到以下错误:

安全处理器无法在邮件中找到安全标头。这可能是因为消息是不安全的错误,或者是因为通信双方之间存在绑定不匹配。如果为安全配置了服务并且客户端未使用安全性,则可能会发生这种情况。

使用以下堆栈跟踪:

at System.ServiceModel.Security.TransportSecurityProtocol.VerifyIncomingMessageCore(Message& message, TimeSpan timeout)
at System.ServiceModel.Security.TransportSecurityProtocol.VerifyIncomingMessage(Message& message, TimeSpan timeout)
at System.ServiceModel.Security.SecurityProtocol.VerifyIncomingMessage(Message& message, TimeSpan timeout, SecurityProtocolCorrelationState[] correlationStates)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MyProject.MyServiceReference.SERVICE_NAME_PortType.WEB_SERVICE_FUNCTION(WEB_SERVICE_FUNCTIONRequest request)
at MyProject.MyServiceReference.SERVICE_NAME_PortTypeClient.MyProject.MyServiceReference.SERVICE_NAME_PortType.WEB_SERVICE_FUNCTION(WEB_SERVICE_FUNCTIONRequest request) in c:\MyProject\Service References\MyServiceReference\Reference.cs:line 981
at MyProject.MyServiceReference.SERVICE_NAME_PortTypeClient.WEB_SERVICE_FUNCTION(SOAHeader SOAHeader, InputParameters2 InputParameters) in c:\MyProject\Service References\MyServiceReference\Reference.cs:line 988
at MyProject.MyClass.MyFunction(String inputParam) in c:\MyProject\MyClass.asmx.cs:line 160

查看堆栈跟踪后,似乎响应的验证可能是导致我相信它可能与其他人遇到的时间戳问题有关的问题(例如http://blog.latamhub.com /?p=78)可能是问题,但是当我尝试将includeTimestamp="true"属性添加到securityWeb.Config 文件中的标记时,VS2012 报告不允许 includeTimestamp 属性。不太确定这里发生了什么或还有什么要检查的。非常感谢任何帮助或想法。

谢谢。

编辑(2013-05-30):

尝试了以下自定义绑定,并将其includeTimestamp设置为 true 和 false,但没有成功:

<customBinding>
    <binding name="SERVICENAME_Binding">
        <security 
            includeTimestamp="true"
        />
    </binding>
</customBinding>
4

0 回答 0