I made a client to consume a web service, in Visual Studio 2010, using WSDL to auto create the proxy classes. In development environment, that is ok, is working fine, because it don’t need to authenticate in this environment.
The problem i have is that the service, in test and production (the true working) environment, it have authentication. The WSDL don’t describe it. Both of them use the same WSDL of development environment.
If i try to view the WSDL, using browser, in test environment, putting the “?WSDL” after the endpoint address, it don’t returns the WSDL, like the development environment. It returns an authentication form, a normal html, and after inform user and password it returns the WSDL (same as development environment).
I made the app.config binding configs like this:
<wsHttpBinding>
<binding name="WebServiceSoapAuth" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<security mode="None">
<transport clientCredentialType="Basic" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</wsHttpBinding>
If i use the basicHttpBinding, that was created automatically by VS 2010 (works in dev environment), my service consumer returns “The security token could not be authenticated or authorized”, as expected.
Changing to wsHttpBinding (code above), it returns “The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: ” followed by the form authentication html code.
I can’t figure what binding configuration i have to use.
I tested the service consumption using SoapUI, and works in both environments, and to it works using authentication, i just had to inform user, password and needed to change the “WSS-Password Type” request config to “PasswordText” (informing just user and password i have the “The security token could not be authenticated or authorized” return).
I’m sorry about my bad english, i’m not fluent, and if i made some mistake in question category or formatting it.
EDIT: I CAN’T VISUALIZE the wsdl file in environment with authentication. When i put address followed by ?WSDL, it gives me a form to authenticate (A form from Ensemble InterSystems software), not the wsdl.
I tested the service consumption using SoapUI, and works in both environments, and to it works using authentication, i just had to inform user, password and needed to change the “WSS-Password Type” request config to “PasswordText” (informing just user and password i have the “The security token could not be authenticated or authorized” return).
Why it does not work using auto generated classes, just informing the user and pass? Someone have idea?
What binding configuration is equivalent to SoapUI configuration’s “WSS-Password Type” equals “PasswordText”? (i guess this is the key of why it doesn’t work if i just inform user and password)
EDIT 2: The body of the soap message is ok. I’m having trouble making the header. It might be something like:
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-5">
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">E1XqZ2v8IDaTBzfF3j/TOA==</wsse:Nonce>
<wsu:Created>2012-12-21T12:24:23.380Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
As i told, i don’t have access to the server, it is at my customer. I just know that it is made in java.
I had to make manually a http webrequest, and had to create the xml manually and passed it to to request. The postData variable comes from the xml manually created.