我需要从 COTS 应用程序中使用 Java Web 服务。我只让 wsdl 使用它。它要求我提供用户名和密码。我以前在我的 .NET 2005 Windows 服务中使用 WSE 3.0 使用它们。我正在尝试将 Windows 服务升级到 2010。
我通过添加服务添加了对服务的引用。(由于公司政策,我不得不更改自定义名称和服务器,所以希望我没有造成语法错误。)我不得不编辑链接,因为这是我的第一篇文章。
我看到它在我的应用配置中添加了条目:
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><system.serviceModel>
<bindings>
<customBinding>
<binding name="MyServiceSoapBinding">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="htp://servername:1234/webservices/thewebservicename"
binding="customBinding" bindingConfiguration="MyServiceSoapBinding"
contract="MyServiceReference.thewebservicename" name="thewebservicenameSoapPort" />
</client>
</system.serviceModel>
我首先尝试使用 BasicHttpBinding:
Dim Binding As BasicHttpBinding
Dim Binding As CustomBinding
Dim EndPoint As EndpointAddress
Dim etFramework As MyServiceReference.thewebserviceClient
Dim rsp As MyServiceReference.MethodResponse
Dim req As MyServiceReference.atkinpovoucherRequest
Dim rsp1 As MyServiceReference.atkinpovoucherResponse
Binding = New BasicHttpBinding()
Binding.Name = "MyServiceSoapBinding"
Binding.Security.Mode = BasicHttpSecurityMode.Message
Binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName
Binding.MessageEncoding = WSMessageEncoding.Mtom
Binding.ReceiveTimeout = New TimeSpan(0, 5, 0)
Binding.OpenTimeout = New TimeSpan(0, 5, 0)
Binding.CloseTimeout = New TimeSpan(0, 5, 0)
Binding.SendTimeout = New TimeSpan(0, 5, 0)
' Set the transport security to UsernameOverTransport for Plaintext usernames
EndPoint = New EndpointAddress("htp://server:1234/webservices/thewebservice")
'Create the SOAP Client (and pass in the endpoint and the binding)
etFramework = New MyServiceReference.thewebserviceClient(Binding, EndPoint)
''Set the username and password
etFramework.ClientCredentials.UserName.UserName = "theusername"
etFramework.ClientCredentials.UserName.Password = "thepassword"
req = New MyServiceReference.theservicenameRequest(strXMLToSubmit)
rsp1 = etFramework.MyServiceReference_thewebservice_theservicename(req)
Debug.WriteLine(rsp1.ToString())
我收到此错误:{“BasicHttp 绑定要求 BasicHttpBinding.Security.Message.ClientCredentialType 等同于安全消息的 BasicHttpMessageCredentialType.Certificate 凭据类型。为 UserName 凭据选择 Transport 或 TransportWithMessageCredential 安全性。”} System.InvalidOperationException: {“BasicHttp 绑定要求 BasicHttpBinding.Security.Message.ClientCredentialType 等效于安全消息的 BasicHttpMessageCredentialType.Certificate 凭据类型。为 UserName 凭据选择 Transport 或 TransportWithMessageCredential 安全性。"}
更改安全模式只会导致不同的错误(需要 Soap 标头;预期 https 不是 http ....)
经过研究,我发现我需要使用 WSHttpBinding。我更改了 Binding 并得到错误:{“响应消息的内容类型 text/xml; charset=utf-8 与绑定的内容类型不匹配 (multipart/related; type="application/xop+xml") . 如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 373 个字节为:'env:VersionMismatchunable to locate Envelope in namespace http://schemas.xmlsoap.org/soap/envelope/. 根元素是命名空间“Envelope”中的“htp://www.w3.org/2003/05/soap-envelope”。”} System.ServiceModel.ProtocolException: {“内容类型 text/xml; 响应消息的 charset=utf-8 与绑定的内容类型不匹配(multipart/related; type="application/xop+xml")。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 373 个字节是:'env:VersionMismatchunable to locate Envelope in namespace htp://schemas.xmlsoap.org/soap/envelope/。根元素是命名空间“Envelope”中的“htp://www.w3.org/2003/05/soap-envelope”。”}
我进行了更多研究,并将 app.config 中的 messageVersion="Soap12" 更改为 messageVersion="Soap11" 并得到相同的错误。我将 WSMessageEncoding 更改为 TEXT 并得到类似的错误消息(绑定是 application/soap+xml)。我能找到的所有研究似乎都在使用 WCF 服务而不是 java。
任何帮助将不胜感激!贝卡