从C#问题访问JAX-WS Web服务

本文关键字:Web 服务 JAX-WS 访问 问题 | 更新日期: 2023-09-27 18:22:21

我必须在VPN网络中使用SOAP web服务(因此您无法测试它),它是用Java(JAX-WSweb服务)编写的。我在服务器端没有访问权限。当我尝试从C#4.0客户端调用web方法时,我得到了以下异常:

  The CustomBinding on the ServiceEndpoint with contract 'ServicesSoap' lacks a TransportBindingElement.  Every binding must have at least one binding element that derives from TransportBindingElement.
at System.ServiceModel.Channels.Binding.EnsureInvariants(String contractName)
   at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose)
   at System.ServiceModel.ChannelFactory.CreateFactory()
   at System.ServiceModel.ChannelFactory.OnOpening()
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ChannelFactory.EnsureOpened()
   at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
   at System.ServiceModel.ClientBase`1.CreateChannel()
   at System.ServiceModel.ClientBase`1.CreateChannelInternal()
   at System.ServiceModel.ClientBase`1.get_Channel()
   at GatewayClient.Lotto.ServicesSoapClient.GatewayClient.Lotto.ServicesSoap.InfoRequest(InfoRequestRequest request)
   at GatewayClient.Lotto.ServicesSoapClient.InfoRequest(infoDataIn request)
   at GatewayClient.MainWindow.InfoRequestButton_Click(Object sender, RoutedEventArgs e)

这是我的app.config:

   <system.serviceModel>
    <bindings>
        <customBinding>
            <binding name="ServicesSoapPortBinding">
                <textMessageEncoding messageVersion="Soap12" />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="http://xxx.yyy/Services"
            binding="customBinding" bindingConfiguration="ServicesSoapPortBinding"
            contract="ServiceReference1.ServicesSoap" name="ServicesSoapPort" />
    </client>
</system.serviceModel>

有什么帮助吗?

从C#问题访问JAX-WS Web服务

我已经解决了在app.config:的binding标记中添加httpTransport的问题

<binding name="ServicesSoapPortBinding">
    <textMessageEncoding messageVersion="Soap12" />
    <httpTransport/>
</binding>

我必须在Visual Studio的"服务引用"功能中添加服务引用。尝试使用svcutil时,我得到了另一个不同的异常。