我需要从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,用于在命名空间http://schemas.xmlsoap.org/soap/envelope/中定位Envelope。根元素是“htp:// www .w3.org / 2003/05 / soap-envelope“在命名空间中”Envelope“'。”} System.ServiceModel.ProtocolException:{“响应消息的内容类型text / xml; charset = utf-8与绑定的内容类型不匹配(multipart / related; type =”application / xop + xml“)。使用自定义编码器,确保正确实现了IsContentTypeSupported方法。响应的前373个字节是:'env:VersionMismatchunable,用于在命名空间中找到信封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。
任何帮助都会非常感激! 贝卡