简体   繁体   中英

SOAP HTTPS Services consume in c#

I am trying to consume HTTPS SOAP Service which has credentials to authorise it and get the below error:

An unhandled exception of type 'System.ServiceModel.ProtocolException' occurred in mscorlib.dll

Additional information: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (text/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: '

Bindings are below. Am I missing anything?

<endpoint address="https://...."
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IInboundService1"
          contract="RQSInboundExternal.IInboundService" name="BasicHttpBinding_IInboundServiceQSPort">

<basicHttpBinding>              
            <binding name="BasicHttpBinding_IInboundService1" >                  
              <security mode="Transport" >
               <transport clientCredentialType="Basic"/>                   
              </security>
            </binding>
        </basicHttpBinding>

set username and password here. This is also required to be sent. If we only send in the header it is not working.

client.ClientCredentials.UserName.UserName = "";
client.ClientCredentials.UserName.Password = "";

var httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(client.ClientCredentials.UserName.UserName + ":" + client.ClientCredentials.UserName.Password));
            client.Open();
            var context = new OperationContext(client.InnerChannel);
            using (new OperationContextScope(context))
            {
                context.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;

                client.SampleMethodCall();
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM