调用Web服务时绑定错误(绑定不匹配?,安全性不匹配?)

时间:2013-05-30 00:08:41

标签: c# .net wcf web-services soa

请原谅我在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>

当对服务进行调用时,我收到以下错误:

  

安全处理器无法在中找到安全标头   信息。这可能是因为消息是不安全的故障或   因为通信方之间存在绑定不匹配。   如果为安全性和服务配置了服务,则会发生这种情况   客户端没有使用安全性。

使用以下stacktrace:

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"属性添加到Web.Config文件中的security标记时,VS2012报告不允许使用includeTimestamp属性。不太确定这里发生了什么或者还有什么要检查。非常感谢任何帮助或想法。

感谢。

编辑(2013-05-30):

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

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

0 个答案:

没有答案